blob: 91fb4569afb8d8528329168419e003b998d7928c [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 */
15
Pere Orga5bc8c002011-04-11 03:29:49 +020016//usage:#define ftpget_trivial_usage
17//usage: "[OPTIONS] HOST [LOCAL_FILE] REMOTE_FILE"
18//usage:#define ftpget_full_usage "\n\n"
Denys Vlasenkocc1bb602012-03-19 12:22:57 +010019//usage: "Download a file via FTP\n"
Pere Orga5bc8c002011-04-11 03:29:49 +020020//usage: IF_FEATURE_FTPGETPUT_LONG_OPTIONS(
Denys Vlasenkocc1bb602012-03-19 12:22:57 +010021//usage: "\n -c,--continue Continue previous transfer"
22//usage: "\n -v,--verbose Verbose"
23//usage: "\n -u,--username USER Username"
24//usage: "\n -p,--password PASS Password"
25//usage: "\n -P,--port NUM Port"
Pere Orga5bc8c002011-04-11 03:29:49 +020026//usage: )
27//usage: IF_NOT_FEATURE_FTPGETPUT_LONG_OPTIONS(
28//usage: "\n -c Continue previous transfer"
29//usage: "\n -v Verbose"
Denys Vlasenkocc1bb602012-03-19 12:22:57 +010030//usage: "\n -u USER Username"
31//usage: "\n -p PASS Password"
32//usage: "\n -P NUM Port"
Pere Orga5bc8c002011-04-11 03:29:49 +020033//usage: )
34//usage:
35//usage:#define ftpput_trivial_usage
36//usage: "[OPTIONS] HOST [REMOTE_FILE] LOCAL_FILE"
37//usage:#define ftpput_full_usage "\n\n"
Denys Vlasenkocc1bb602012-03-19 12:22:57 +010038//usage: "Upload a file to a FTP server\n"
Pere Orga5bc8c002011-04-11 03:29:49 +020039//usage: IF_FEATURE_FTPGETPUT_LONG_OPTIONS(
Denys Vlasenkocc1bb602012-03-19 12:22:57 +010040//usage: "\n -v,--verbose Verbose"
41//usage: "\n -u,--username USER Username"
42//usage: "\n -p,--password PASS Password"
43//usage: "\n -P,--port NUM Port"
Pere Orga5bc8c002011-04-11 03:29:49 +020044//usage: )
45//usage: IF_NOT_FEATURE_FTPGETPUT_LONG_OPTIONS(
46//usage: "\n -v Verbose"
Denys Vlasenkocc1bb602012-03-19 12:22:57 +010047//usage: "\n -u USER Username"
48//usage: "\n -p PASS Password"
49//usage: "\n -P NUM Port number"
Pere Orga5bc8c002011-04-11 03:29:49 +020050//usage: )
51
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000052#include "libbb.h"
Denys Vlasenkoe6a2f4c2016-04-21 16:26:30 +020053#include "common_bufsiz.h"
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000054
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000055struct globals {
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +000056 const char *user;
57 const char *password;
Denis Vlasenko8e9ccba2007-01-11 16:50:23 +000058 struct len_and_sockaddr *lsa;
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000059 FILE *control_stream;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000060 int verbose_flag;
61 int do_continue;
Denys Vlasenko60a94142011-05-13 20:57:01 +020062 char buf[4]; /* actually [BUFSZ] */
Denys Vlasenko98a4c7c2010-02-04 15:00:15 +010063} FIX_ALIASING;
Denys Vlasenkoe6a2f4c2016-04-21 16:26:30 +020064#define G (*(struct globals*)bb_common_bufsiz1)
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000065enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) };
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000066#define user (G.user )
67#define password (G.password )
68#define lsa (G.lsa )
69#define control_stream (G.control_stream)
70#define verbose_flag (G.verbose_flag )
71#define do_continue (G.do_continue )
72#define buf (G.buf )
Denys Vlasenkoab3964d2015-10-13 14:50:20 +020073#define INIT_G() do { \
Denys Vlasenko47cfbf32016-04-21 18:18:48 +020074 setup_common_bufsiz(); \
Denys Vlasenkoab3964d2015-10-13 14:50:20 +020075 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
76} while (0)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000077
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000078
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000079static void ftp_die(const char *msg) NORETURN;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000080static void ftp_die(const char *msg)
Denis Vlasenko562dc242007-01-03 21:55:50 +000081{
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000082 char *cp = buf; /* buf holds peer's response */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000083
Denis Vlasenko562dc242007-01-03 21:55:50 +000084 /* Guard against garbage from remote server */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000085 while (*cp >= ' ' && *cp < '\x7f')
86 cp++;
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000087 *cp = '\0';
88 bb_error_msg_and_die("unexpected server response%s%s: %s",
89 (msg ? " to " : ""), (msg ? msg : ""), buf);
Denis Vlasenko562dc242007-01-03 21:55:50 +000090}
91
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000092static int ftpcmd(const char *s1, const char *s2)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000093{
Denis Vlasenko562dc242007-01-03 21:55:50 +000094 unsigned n;
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000095
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000096 if (verbose_flag) {
Denis Vlasenko3821fb12007-01-11 16:51:21 +000097 bb_error_msg("cmd %s %s", s1, s2);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000098 }
99
100 if (s1) {
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000101 fprintf(control_stream, (s2 ? "%s %s\r\n" : "%s %s\r\n"+3),
102 s1, s2);
103 fflush(control_stream);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000104 }
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000105
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000106 do {
Denys Vlasenko60a94142011-05-13 20:57:01 +0200107 strcpy(buf, "EOF"); /* for ftp_die */
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000108 if (fgets(buf, BUFSZ - 2, control_stream) == NULL) {
109 ftp_die(NULL);
Glenn L McGrath5ec58282004-05-04 10:43:34 +0000110 }
Denis Vlasenko13858992006-10-08 12:49:22 +0000111 } while (!isdigit(buf[0]) || buf[3] != ' ');
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000112
Denis Vlasenko562dc242007-01-03 21:55:50 +0000113 buf[3] = '\0';
114 n = xatou(buf);
115 buf[3] = ' ';
116 return n;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000117}
118
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000119static void ftp_login(void)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000120{
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000121 /* Connect to the command socket */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000122 control_stream = fdopen(xconnect_stream(lsa), "r+");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000123 if (control_stream == NULL) {
Denis Vlasenko8e9ccba2007-01-11 16:50:23 +0000124 /* fdopen failed - extremely unlikely */
Denis Vlasenko562dc242007-01-03 21:55:50 +0000125 bb_perror_nomsg_and_die();
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000126 }
127
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000128 if (ftpcmd(NULL, NULL) != 220) {
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000129 ftp_die(NULL);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000130 }
131
132 /* Login to the server */
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000133 switch (ftpcmd("USER", user)) {
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000134 case 230:
135 break;
136 case 331:
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000137 if (ftpcmd("PASS", password) != 230) {
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000138 ftp_die("PASS");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000139 }
140 break;
141 default:
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000142 ftp_die("USER");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000143 }
144
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000145 ftpcmd("TYPE I", NULL);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000146}
147
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000148static int xconnect_ftpdata(void)
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000149{
150 char *buf_ptr;
151 unsigned port_num;
152
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000153/*
154TODO: PASV command will not work for IPv6. RFC2428 describes
155IPv6-capable "extended PASV" - EPSV.
156
157"EPSV [protocol]" asks server to bind to and listen on a data port
158in specified protocol. Protocol is 1 for IPv4, 2 for IPv6.
159If not specified, defaults to "same as used for control connection".
160If server understood you, it should answer "229 <some text>(|||port|)"
161where "|" are literal pipe chars and "port" is ASCII decimal port#.
162
163There is also an IPv6-capable replacement for PORT (EPRT),
164but we don't need that.
165
166NB: PASV may still work for some servers even over IPv6.
167For example, vsftp happily answers
168"227 Entering Passive Mode (0,0,0,0,n,n)" and proceeds as usual.
169
170TODO2: need to stop ignoring IP address in PASV response.
171*/
172
173 if (ftpcmd("PASV", NULL) != 227) {
174 ftp_die("PASV");
175 }
176
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000177 /* Response is "NNN garbageN1,N2,N3,N4,P1,P2[)garbage]
178 * Server's IP is N1.N2.N3.N4 (we ignore it)
179 * Server's port for data connection is P1*256+P2 */
180 buf_ptr = strrchr(buf, ')');
181 if (buf_ptr) *buf_ptr = '\0';
182
183 buf_ptr = strrchr(buf, ',');
184 *buf_ptr = '\0';
185 port_num = xatoul_range(buf_ptr + 1, 0, 255);
186
187 buf_ptr = strrchr(buf, ',');
188 *buf_ptr = '\0';
189 port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256;
190
Denys Vlasenkoca183112011-04-07 17:52:20 +0200191 set_nport(&lsa->u.sa, htons(port_num));
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000192 return xconnect_stream(lsa);
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000193}
194
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000195static int pump_data_and_QUIT(int from, int to)
196{
197 /* copy the file */
198 if (bb_copyfd_eof(from, to) == -1) {
199 /* error msg is already printed by bb_copyfd_eof */
200 return EXIT_FAILURE;
201 }
202
203 /* close data connection */
204 close(from); /* don't know which one is that, so we close both */
205 close(to);
206
207 /* does server confirm that transfer is finished? */
208 if (ftpcmd(NULL, NULL) != 226) {
209 ftp_die(NULL);
210 }
211 ftpcmd("QUIT", NULL);
212
213 return EXIT_SUCCESS;
214}
215
Rob Landleyb1c3fbc2006-05-04 19:52:28 +0000216#if !ENABLE_FTPGET
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000217int ftp_receive(const char *local_path, char *server_path);
Rob Landleyb1c3fbc2006-05-04 19:52:28 +0000218#else
Denis Vlasenko7039a662006-10-08 17:54:47 +0000219static
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000220int ftp_receive(const char *local_path, char *server_path)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000221{
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000222 int fd_data;
Glenn L McGrath236e93d2003-12-20 05:43:34 +0000223 int fd_local = -1;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000224 off_t beg_range = 0;
225
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000226 /* connect to the data socket */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000227 fd_data = xconnect_ftpdata();
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000228
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000229 if (ftpcmd("SIZE", server_path) != 213) {
Rob Landleybc059bc2006-01-10 06:36:00 +0000230 do_continue = 0;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000231 }
232
Denis Vlasenko9f739442006-12-16 23:49:13 +0000233 if (LONE_DASH(local_path)) {
Eric Andersen70060d22004-03-27 10:02:48 +0000234 fd_local = STDOUT_FILENO;
Glenn L McGrath236e93d2003-12-20 05:43:34 +0000235 do_continue = 0;
236 }
237
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000238 if (do_continue) {
239 struct stat sbuf;
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000240 /* lstat would be wrong here! */
241 if (stat(local_path, &sbuf) < 0) {
242 bb_perror_msg_and_die("stat");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000243 }
244 if (sbuf.st_size > 0) {
245 beg_range = sbuf.st_size;
246 } else {
247 do_continue = 0;
248 }
249 }
250
251 if (do_continue) {
Denys Vlasenkoa3aa3e32009-12-11 12:36:10 +0100252 sprintf(buf, "REST %"OFF_FMT"u", beg_range);
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000253 if (ftpcmd(buf, NULL) != 350) {
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000254 do_continue = 0;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000255 }
256 }
257
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000258 if (ftpcmd("RETR", server_path) > 150) {
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000259 ftp_die("RETR");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000260 }
261
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000262 /* create local file _after_ we know that remote file exists */
Glenn L McGrath236e93d2003-12-20 05:43:34 +0000263 if (fd_local == -1) {
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000264 fd_local = xopen(local_path,
265 do_continue ? (O_APPEND | O_WRONLY)
266 : (O_CREAT | O_TRUNC | O_WRONLY)
267 );
Glenn L McGrath1643f412002-12-18 02:47:40 +0000268 }
269
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000270 return pump_data_and_QUIT(fd_data, fd_local);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000271}
272#endif
273
Rob Landleyb1c3fbc2006-05-04 19:52:28 +0000274#if !ENABLE_FTPPUT
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000275int ftp_send(const char *server_path, char *local_path);
Rob Landleyb1c3fbc2006-05-04 19:52:28 +0000276#else
Denis Vlasenko7039a662006-10-08 17:54:47 +0000277static
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000278int ftp_send(const char *server_path, char *local_path)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000279{
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000280 int fd_data;
281 int fd_local;
282 int response;
283
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000284 /* connect to the data socket */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000285 fd_data = xconnect_ftpdata();
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000286
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000287 /* get the local file */
Denis Vlasenko9f739442006-12-16 23:49:13 +0000288 fd_local = STDIN_FILENO;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000289 if (NOT_LONE_DASH(local_path))
Rob Landleyd921b2e2006-08-03 15:41:12 +0000290 fd_local = xopen(local_path, O_RDONLY);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000291
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000292 response = ftpcmd("STOR", server_path);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000293 switch (response) {
294 case 125:
295 case 150:
296 break;
297 default:
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000298 ftp_die("STOR");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000299 }
300
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000301 return pump_data_and_QUIT(fd_local, fd_data);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000302}
303#endif
304
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +0000305#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
Denis Vlasenko6ca409e2007-08-12 20:58:27 +0000306static const char ftpgetput_longopts[] ALIGN1 =
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +0000307 "continue\0" Required_argument "c"
308 "verbose\0" No_argument "v"
309 "username\0" Required_argument "u"
310 "password\0" Required_argument "p"
311 "port\0" Required_argument "P"
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000312 ;
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +0000313#endif
Glenn L McGrathb51eb262003-12-19 10:37:52 +0000314
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000315int ftpgetput_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000316int ftpgetput_main(int argc UNUSED_PARAM, char **argv)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000317{
Denis Vlasenko562dc242007-01-03 21:55:50 +0000318 const char *port = "ftp";
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000319 /* socket to ftp server */
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000320
Denis Vlasenko562dc242007-01-03 21:55:50 +0000321#if ENABLE_FTPPUT && !ENABLE_FTPGET
322# define ftp_action ftp_send
323#elif ENABLE_FTPGET && !ENABLE_FTPPUT
324# define ftp_action ftp_receive
325#else
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000326 int (*ftp_action)(const char *, char *) = ftp_send;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000327
Glenn L McGrath266c1f52003-12-20 03:19:27 +0000328 /* Check to see if the command is ftpget or ftput */
Denis Vlasenko562dc242007-01-03 21:55:50 +0000329 if (applet_name[3] == 'g') {
Bernhard Reutner-Fischere0387a62006-06-07 13:31:59 +0000330 ftp_action = ftp_receive;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000331 }
Denis Vlasenko562dc242007-01-03 21:55:50 +0000332#endif
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000333
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000334 INIT_G();
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000335 /* Set default values */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000336 user = "anonymous";
337 password = "busybox@";
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000338
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000339 /*
340 * Decipher the command line
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000341 */
Denis Vlasenkoc61852a2006-11-29 11:09:43 +0000342#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +0000343 applet_long_options = ftpgetput_longopts;
Denis Vlasenkoc61852a2006-11-29 11:09:43 +0000344#endif
Vladimir Dronnikov1dacfbb2009-10-23 23:34:43 +0200345 opt_complementary = "-2:vv:cc"; /* must have 2 to 3 params; -v and -c count */
Denys Vlasenko60a94142011-05-13 20:57:01 +0200346 getopt32(argv, "cvu:p:P:", &user, &password, &port,
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000347 &verbose_flag, &do_continue);
Denis Vlasenko562dc242007-01-03 21:55:50 +0000348 argv += optind;
Glenn L McGrath236e93d2003-12-20 05:43:34 +0000349
Eric Andersen04d055f2003-11-03 21:20:18 +0000350 /* We want to do exactly _one_ DNS lookup, since some
351 * sites (i.e. ftp.us.debian.org) use round-robin DNS
352 * and we want to connect to only one IP... */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000353 lsa = xhost2sockaddr(argv[0], bb_lookup_port(port, "tcp", 21));
Eric Andersen04d055f2003-11-03 21:20:18 +0000354 if (verbose_flag) {
Denis Vlasenko85629f02007-01-22 09:36:41 +0000355 printf("Connecting to %s (%s)\n", argv[0],
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000356 xmalloc_sockaddr2dotted(&lsa->u.sa));
Eric Andersen04d055f2003-11-03 21:20:18 +0000357 }
358
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000359 ftp_login();
Vladimir Dronnikov1dacfbb2009-10-23 23:34:43 +0200360 return ftp_action(argv[1], argv[2] ? argv[2] : argv[1]);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000361}