blob: 2f2921366812859fa3241255c42f93d02ea57159 [file] [log] [blame]
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +00001/* vi: set sw=4 ts=4: */
2/*
Eric Andersenc7bda1c2004-03-15 08:29:22 +00003 * ftpget
4 *
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +00005 * Mini implementation of FTP to retrieve a remote file.
6 *
7 * Copyright (C) 2002 Jeff Angielski, The PTR Group <jeff@theptrgroup.com>
Denis Vlasenko0beaff82007-09-21 13:16:32 +00008 * Copyright (C) 2002 Glenn McGrath
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +00009 *
10 * Based on wget.c by Chip Rosenthal Covad Communications
11 * <chip@laserlink.net>
12 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +020013 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000014 */
Denys Vlasenko47367e12016-11-23 09:05:14 +010015//config:config FTPGET
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020016//config: bool "ftpget (8 kb)"
Denys Vlasenko47367e12016-11-23 09:05:14 +010017//config: default y
18//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020019//config: Retrieve a remote file via FTP.
Denys Vlasenko47367e12016-11-23 09:05:14 +010020//config:
21//config:config FTPPUT
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020022//config: bool "ftpput (7.7 kb)"
Denys Vlasenko47367e12016-11-23 09:05:14 +010023//config: default y
24//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020025//config: Store a remote file via FTP.
Denys Vlasenko47367e12016-11-23 09:05:14 +010026//config:
27//config:config FEATURE_FTPGETPUT_LONG_OPTIONS
28//config: bool "Enable long options in ftpget/ftpput"
29//config: default y
30//config: depends on LONG_OPTS && (FTPGET || FTPPUT)
Denys Vlasenko47367e12016-11-23 09:05:14 +010031
32//applet:IF_FTPGET(APPLET_ODDNAME(ftpget, ftpgetput, BB_DIR_USR_BIN, BB_SUID_DROP, ftpget))
33//applet:IF_FTPPUT(APPLET_ODDNAME(ftpput, ftpgetput, BB_DIR_USR_BIN, BB_SUID_DROP, ftpput))
34
35//kbuild:lib-$(CONFIG_FTPGET) += ftpgetput.o
36//kbuild:lib-$(CONFIG_FTPPUT) += ftpgetput.o
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000037
Pere Orga5bc8c002011-04-11 03:29:49 +020038//usage:#define ftpget_trivial_usage
39//usage: "[OPTIONS] HOST [LOCAL_FILE] REMOTE_FILE"
40//usage:#define ftpget_full_usage "\n\n"
Denys Vlasenkocc1bb602012-03-19 12:22:57 +010041//usage: "Download a file via FTP\n"
Pere Orga5bc8c002011-04-11 03:29:49 +020042//usage: "\n -c Continue previous transfer"
43//usage: "\n -v Verbose"
Denys Vlasenkocc1bb602012-03-19 12:22:57 +010044//usage: "\n -u USER Username"
45//usage: "\n -p PASS Password"
46//usage: "\n -P NUM Port"
Pere Orga5bc8c002011-04-11 03:29:49 +020047//usage:
48//usage:#define ftpput_trivial_usage
49//usage: "[OPTIONS] HOST [REMOTE_FILE] LOCAL_FILE"
50//usage:#define ftpput_full_usage "\n\n"
Denys Vlasenkocc1bb602012-03-19 12:22:57 +010051//usage: "Upload a file to a FTP server\n"
Pere Orga5bc8c002011-04-11 03:29:49 +020052//usage: "\n -v Verbose"
Denys Vlasenkocc1bb602012-03-19 12:22:57 +010053//usage: "\n -u USER Username"
54//usage: "\n -p PASS Password"
55//usage: "\n -P NUM Port number"
Pere Orga5bc8c002011-04-11 03:29:49 +020056
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000057#include "libbb.h"
Denys Vlasenkoe6a2f4c2016-04-21 16:26:30 +020058#include "common_bufsiz.h"
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000059
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000060struct globals {
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +000061 const char *user;
62 const char *password;
Denis Vlasenko8e9ccba2007-01-11 16:50:23 +000063 struct len_and_sockaddr *lsa;
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000064 FILE *control_stream;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000065 int verbose_flag;
66 int do_continue;
Denys Vlasenko60a94142011-05-13 20:57:01 +020067 char buf[4]; /* actually [BUFSZ] */
Denys Vlasenko98a4c7c2010-02-04 15:00:15 +010068} FIX_ALIASING;
Denys Vlasenkoe6a2f4c2016-04-21 16:26:30 +020069#define G (*(struct globals*)bb_common_bufsiz1)
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000070enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) };
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000071#define user (G.user )
72#define password (G.password )
73#define lsa (G.lsa )
74#define control_stream (G.control_stream)
75#define verbose_flag (G.verbose_flag )
76#define do_continue (G.do_continue )
77#define buf (G.buf )
Denys Vlasenkoab3964d2015-10-13 14:50:20 +020078#define INIT_G() do { \
Denys Vlasenko47cfbf32016-04-21 18:18:48 +020079 setup_common_bufsiz(); \
Denys Vlasenkoab3964d2015-10-13 14:50:20 +020080 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
81} while (0)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000082
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000083
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000084static void ftp_die(const char *msg) NORETURN;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000085static void ftp_die(const char *msg)
Denis Vlasenko562dc242007-01-03 21:55:50 +000086{
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000087 char *cp = buf; /* buf holds peer's response */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000088
Denis Vlasenko562dc242007-01-03 21:55:50 +000089 /* Guard against garbage from remote server */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000090 while (*cp >= ' ' && *cp < '\x7f')
91 cp++;
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000092 *cp = '\0';
93 bb_error_msg_and_die("unexpected server response%s%s: %s",
94 (msg ? " to " : ""), (msg ? msg : ""), buf);
Denis Vlasenko562dc242007-01-03 21:55:50 +000095}
96
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000097static int ftpcmd(const char *s1, const char *s2)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000098{
Denis Vlasenko562dc242007-01-03 21:55:50 +000099 unsigned n;
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000100
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000101 if (verbose_flag) {
Denis Vlasenko3821fb12007-01-11 16:51:21 +0000102 bb_error_msg("cmd %s %s", s1, s2);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000103 }
104
105 if (s1) {
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000106 fprintf(control_stream, (s2 ? "%s %s\r\n" : "%s %s\r\n"+3),
107 s1, s2);
108 fflush(control_stream);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000109 }
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000110
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000111 do {
Denys Vlasenko60a94142011-05-13 20:57:01 +0200112 strcpy(buf, "EOF"); /* for ftp_die */
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000113 if (fgets(buf, BUFSZ - 2, control_stream) == NULL) {
114 ftp_die(NULL);
Glenn L McGrath5ec58282004-05-04 10:43:34 +0000115 }
Denis Vlasenko13858992006-10-08 12:49:22 +0000116 } while (!isdigit(buf[0]) || buf[3] != ' ');
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000117
Denis Vlasenko562dc242007-01-03 21:55:50 +0000118 buf[3] = '\0';
119 n = xatou(buf);
120 buf[3] = ' ';
121 return n;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000122}
123
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000124static void ftp_login(void)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000125{
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000126 /* Connect to the command socket */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000127 control_stream = fdopen(xconnect_stream(lsa), "r+");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000128 if (control_stream == NULL) {
Denis Vlasenko8e9ccba2007-01-11 16:50:23 +0000129 /* fdopen failed - extremely unlikely */
Denis Vlasenko562dc242007-01-03 21:55:50 +0000130 bb_perror_nomsg_and_die();
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000131 }
132
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000133 if (ftpcmd(NULL, NULL) != 220) {
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000134 ftp_die(NULL);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000135 }
136
137 /* Login to the server */
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000138 switch (ftpcmd("USER", user)) {
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000139 case 230:
140 break;
141 case 331:
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000142 if (ftpcmd("PASS", password) != 230) {
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000143 ftp_die("PASS");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000144 }
145 break;
146 default:
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000147 ftp_die("USER");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000148 }
149
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000150 ftpcmd("TYPE I", NULL);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000151}
152
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000153static int xconnect_ftpdata(void)
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000154{
Denys Vlasenko1783ffa2018-02-06 15:48:12 +0100155 int port_num;
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000156
Denys Vlasenko1783ffa2018-02-06 15:48:12 +0100157 if (ENABLE_FEATURE_IPV6 && ftpcmd("EPSV", NULL) == 229) {
158 /* good */
159 } else if (ftpcmd("PASV", NULL) != 227) {
160 ftp_die("PASV");
Denys Vlasenko05b84d42018-02-04 19:08:34 +0100161 }
Denys Vlasenko1783ffa2018-02-06 15:48:12 +0100162 port_num = parse_pasv_epsv(buf);
163 if (port_num < 0)
164 ftp_die("PASV");
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000165
Denys Vlasenkoca183112011-04-07 17:52:20 +0200166 set_nport(&lsa->u.sa, htons(port_num));
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000167 return xconnect_stream(lsa);
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000168}
169
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000170static int pump_data_and_QUIT(int from, int to)
171{
172 /* copy the file */
173 if (bb_copyfd_eof(from, to) == -1) {
174 /* error msg is already printed by bb_copyfd_eof */
175 return EXIT_FAILURE;
176 }
177
178 /* close data connection */
179 close(from); /* don't know which one is that, so we close both */
180 close(to);
181
182 /* does server confirm that transfer is finished? */
183 if (ftpcmd(NULL, NULL) != 226) {
184 ftp_die(NULL);
185 }
186 ftpcmd("QUIT", NULL);
187
188 return EXIT_SUCCESS;
189}
190
Rob Landleyb1c3fbc2006-05-04 19:52:28 +0000191#if !ENABLE_FTPGET
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000192int ftp_receive(const char *local_path, char *server_path);
Rob Landleyb1c3fbc2006-05-04 19:52:28 +0000193#else
Denis Vlasenko7039a662006-10-08 17:54:47 +0000194static
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000195int ftp_receive(const char *local_path, char *server_path)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000196{
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000197 int fd_data;
Glenn L McGrath236e93d2003-12-20 05:43:34 +0000198 int fd_local = -1;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000199 off_t beg_range = 0;
200
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000201 /* connect to the data socket */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000202 fd_data = xconnect_ftpdata();
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000203
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000204 if (ftpcmd("SIZE", server_path) != 213) {
Rob Landleybc059bc2006-01-10 06:36:00 +0000205 do_continue = 0;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000206 }
207
Denis Vlasenko9f739442006-12-16 23:49:13 +0000208 if (LONE_DASH(local_path)) {
Eric Andersen70060d22004-03-27 10:02:48 +0000209 fd_local = STDOUT_FILENO;
Glenn L McGrath236e93d2003-12-20 05:43:34 +0000210 do_continue = 0;
211 }
212
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000213 if (do_continue) {
214 struct stat sbuf;
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000215 /* lstat would be wrong here! */
216 if (stat(local_path, &sbuf) < 0) {
217 bb_perror_msg_and_die("stat");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000218 }
219 if (sbuf.st_size > 0) {
220 beg_range = sbuf.st_size;
221 } else {
222 do_continue = 0;
223 }
224 }
225
226 if (do_continue) {
Denys Vlasenkoa3aa3e32009-12-11 12:36:10 +0100227 sprintf(buf, "REST %"OFF_FMT"u", beg_range);
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000228 if (ftpcmd(buf, NULL) != 350) {
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000229 do_continue = 0;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000230 }
231 }
232
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000233 if (ftpcmd("RETR", server_path) > 150) {
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000234 ftp_die("RETR");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000235 }
236
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000237 /* create local file _after_ we know that remote file exists */
Glenn L McGrath236e93d2003-12-20 05:43:34 +0000238 if (fd_local == -1) {
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000239 fd_local = xopen(local_path,
240 do_continue ? (O_APPEND | O_WRONLY)
241 : (O_CREAT | O_TRUNC | O_WRONLY)
242 );
Glenn L McGrath1643f412002-12-18 02:47:40 +0000243 }
244
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000245 return pump_data_and_QUIT(fd_data, fd_local);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000246}
247#endif
248
Rob Landleyb1c3fbc2006-05-04 19:52:28 +0000249#if !ENABLE_FTPPUT
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000250int ftp_send(const char *server_path, char *local_path);
Rob Landleyb1c3fbc2006-05-04 19:52:28 +0000251#else
Denis Vlasenko7039a662006-10-08 17:54:47 +0000252static
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000253int ftp_send(const char *server_path, char *local_path)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000254{
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000255 int fd_data;
256 int fd_local;
257 int response;
258
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000259 /* connect to the data socket */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000260 fd_data = xconnect_ftpdata();
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000261
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000262 /* get the local file */
Denis Vlasenko9f739442006-12-16 23:49:13 +0000263 fd_local = STDIN_FILENO;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000264 if (NOT_LONE_DASH(local_path))
Rob Landleyd921b2e2006-08-03 15:41:12 +0000265 fd_local = xopen(local_path, O_RDONLY);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000266
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000267 response = ftpcmd("STOR", server_path);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000268 switch (response) {
269 case 125:
270 case 150:
271 break;
272 default:
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000273 ftp_die("STOR");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000274 }
275
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000276 return pump_data_and_QUIT(fd_local, fd_data);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000277}
278#endif
279
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +0000280#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
Denis Vlasenko6ca409e2007-08-12 20:58:27 +0000281static const char ftpgetput_longopts[] ALIGN1 =
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +0000282 "continue\0" Required_argument "c"
283 "verbose\0" No_argument "v"
284 "username\0" Required_argument "u"
285 "password\0" Required_argument "p"
286 "port\0" Required_argument "P"
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000287 ;
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +0000288#endif
Glenn L McGrathb51eb262003-12-19 10:37:52 +0000289
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000290int ftpgetput_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000291int ftpgetput_main(int argc UNUSED_PARAM, char **argv)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000292{
Denis Vlasenko562dc242007-01-03 21:55:50 +0000293 const char *port = "ftp";
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000294 /* socket to ftp server */
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000295
Denis Vlasenko562dc242007-01-03 21:55:50 +0000296#if ENABLE_FTPPUT && !ENABLE_FTPGET
297# define ftp_action ftp_send
298#elif ENABLE_FTPGET && !ENABLE_FTPPUT
299# define ftp_action ftp_receive
300#else
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000301 int (*ftp_action)(const char *, char *) = ftp_send;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000302
Glenn L McGrath266c1f52003-12-20 03:19:27 +0000303 /* Check to see if the command is ftpget or ftput */
Denis Vlasenko562dc242007-01-03 21:55:50 +0000304 if (applet_name[3] == 'g') {
Bernhard Reutner-Fischere0387a62006-06-07 13:31:59 +0000305 ftp_action = ftp_receive;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000306 }
Denis Vlasenko562dc242007-01-03 21:55:50 +0000307#endif
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000308
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000309 INIT_G();
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000310 /* Set default values */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000311 user = "anonymous";
Denys Vlasenko32c3e3a2018-04-07 13:22:52 +0200312 password = "busybox";
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000313
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000314 /*
315 * Decipher the command line
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000316 */
Denys Vlasenko22542ec2017-08-08 21:55:02 +0200317 /* must have 2 to 3 params; -v and -c count */
318#define OPTSTRING "^cvu:p:P:" "\0" "-2:?3:vv:cc"
Denys Vlasenko036585a2017-08-08 16:38:18 +0200319#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
Denys Vlasenko22542ec2017-08-08 21:55:02 +0200320 getopt32long(argv, OPTSTRING, ftpgetput_longopts,
Denys Vlasenko036585a2017-08-08 16:38:18 +0200321#else
Denys Vlasenko22542ec2017-08-08 21:55:02 +0200322 getopt32(argv, OPTSTRING,
Denys Vlasenko036585a2017-08-08 16:38:18 +0200323#endif
324 &user, &password, &port, &verbose_flag, &do_continue
325 );
Denis Vlasenko562dc242007-01-03 21:55:50 +0000326 argv += optind;
Glenn L McGrath236e93d2003-12-20 05:43:34 +0000327
Eric Andersen04d055f2003-11-03 21:20:18 +0000328 /* We want to do exactly _one_ DNS lookup, since some
329 * sites (i.e. ftp.us.debian.org) use round-robin DNS
330 * and we want to connect to only one IP... */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000331 lsa = xhost2sockaddr(argv[0], bb_lookup_port(port, "tcp", 21));
Eric Andersen04d055f2003-11-03 21:20:18 +0000332 if (verbose_flag) {
Denis Vlasenko85629f02007-01-22 09:36:41 +0000333 printf("Connecting to %s (%s)\n", argv[0],
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000334 xmalloc_sockaddr2dotted(&lsa->u.sa));
Eric Andersen04d055f2003-11-03 21:20:18 +0000335 }
336
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000337 ftp_login();
Vladimir Dronnikov1dacfbb2009-10-23 23:34:43 +0200338 return ftp_action(argv[1], argv[2] ? argv[2] : argv[1]);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000339}