blob: b398bc8742f79f534ef219052994571bf5390e30 [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"
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000053
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000054struct globals {
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +000055 const char *user;
56 const char *password;
Denis Vlasenko8e9ccba2007-01-11 16:50:23 +000057 struct len_and_sockaddr *lsa;
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000058 FILE *control_stream;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000059 int verbose_flag;
60 int do_continue;
Denys Vlasenko60a94142011-05-13 20:57:01 +020061 char buf[4]; /* actually [BUFSZ] */
Denys Vlasenko98a4c7c2010-02-04 15:00:15 +010062} FIX_ALIASING;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000063#define G (*(struct globals*)&bb_common_bufsiz1)
64enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) };
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000065#define user (G.user )
66#define password (G.password )
67#define lsa (G.lsa )
68#define control_stream (G.control_stream)
69#define verbose_flag (G.verbose_flag )
70#define do_continue (G.do_continue )
71#define buf (G.buf )
Denys Vlasenkoab3964d2015-10-13 14:50:20 +020072#define INIT_G() do { \
73 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
74} while (0)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000075
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000076
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000077static void ftp_die(const char *msg) NORETURN;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000078static void ftp_die(const char *msg)
Denis Vlasenko562dc242007-01-03 21:55:50 +000079{
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000080 char *cp = buf; /* buf holds peer's response */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000081
Denis Vlasenko562dc242007-01-03 21:55:50 +000082 /* Guard against garbage from remote server */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +000083 while (*cp >= ' ' && *cp < '\x7f')
84 cp++;
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000085 *cp = '\0';
86 bb_error_msg_and_die("unexpected server response%s%s: %s",
87 (msg ? " to " : ""), (msg ? msg : ""), buf);
Denis Vlasenko562dc242007-01-03 21:55:50 +000088}
89
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000090static int ftpcmd(const char *s1, const char *s2)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000091{
Denis Vlasenko562dc242007-01-03 21:55:50 +000092 unsigned n;
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000093
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000094 if (verbose_flag) {
Denis Vlasenko3821fb12007-01-11 16:51:21 +000095 bb_error_msg("cmd %s %s", s1, s2);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +000096 }
97
98 if (s1) {
Denis Vlasenko7cb808e2008-03-29 07:40:35 +000099 fprintf(control_stream, (s2 ? "%s %s\r\n" : "%s %s\r\n"+3),
100 s1, s2);
101 fflush(control_stream);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000102 }
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000103
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000104 do {
Denys Vlasenko60a94142011-05-13 20:57:01 +0200105 strcpy(buf, "EOF"); /* for ftp_die */
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000106 if (fgets(buf, BUFSZ - 2, control_stream) == NULL) {
107 ftp_die(NULL);
Glenn L McGrath5ec58282004-05-04 10:43:34 +0000108 }
Denis Vlasenko13858992006-10-08 12:49:22 +0000109 } while (!isdigit(buf[0]) || buf[3] != ' ');
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000110
Denis Vlasenko562dc242007-01-03 21:55:50 +0000111 buf[3] = '\0';
112 n = xatou(buf);
113 buf[3] = ' ';
114 return n;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000115}
116
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000117static void ftp_login(void)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000118{
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000119 /* Connect to the command socket */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000120 control_stream = fdopen(xconnect_stream(lsa), "r+");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000121 if (control_stream == NULL) {
Denis Vlasenko8e9ccba2007-01-11 16:50:23 +0000122 /* fdopen failed - extremely unlikely */
Denis Vlasenko562dc242007-01-03 21:55:50 +0000123 bb_perror_nomsg_and_die();
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000124 }
125
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000126 if (ftpcmd(NULL, NULL) != 220) {
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000127 ftp_die(NULL);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000128 }
129
130 /* Login to the server */
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000131 switch (ftpcmd("USER", user)) {
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000132 case 230:
133 break;
134 case 331:
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000135 if (ftpcmd("PASS", password) != 230) {
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000136 ftp_die("PASS");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000137 }
138 break;
139 default:
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000140 ftp_die("USER");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000141 }
142
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000143 ftpcmd("TYPE I", NULL);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000144}
145
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000146static int xconnect_ftpdata(void)
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000147{
148 char *buf_ptr;
149 unsigned port_num;
150
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000151/*
152TODO: PASV command will not work for IPv6. RFC2428 describes
153IPv6-capable "extended PASV" - EPSV.
154
155"EPSV [protocol]" asks server to bind to and listen on a data port
156in specified protocol. Protocol is 1 for IPv4, 2 for IPv6.
157If not specified, defaults to "same as used for control connection".
158If server understood you, it should answer "229 <some text>(|||port|)"
159where "|" are literal pipe chars and "port" is ASCII decimal port#.
160
161There is also an IPv6-capable replacement for PORT (EPRT),
162but we don't need that.
163
164NB: PASV may still work for some servers even over IPv6.
165For example, vsftp happily answers
166"227 Entering Passive Mode (0,0,0,0,n,n)" and proceeds as usual.
167
168TODO2: need to stop ignoring IP address in PASV response.
169*/
170
171 if (ftpcmd("PASV", NULL) != 227) {
172 ftp_die("PASV");
173 }
174
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000175 /* Response is "NNN garbageN1,N2,N3,N4,P1,P2[)garbage]
176 * Server's IP is N1.N2.N3.N4 (we ignore it)
177 * Server's port for data connection is P1*256+P2 */
178 buf_ptr = strrchr(buf, ')');
179 if (buf_ptr) *buf_ptr = '\0';
180
181 buf_ptr = strrchr(buf, ',');
182 *buf_ptr = '\0';
183 port_num = xatoul_range(buf_ptr + 1, 0, 255);
184
185 buf_ptr = strrchr(buf, ',');
186 *buf_ptr = '\0';
187 port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256;
188
Denys Vlasenkoca183112011-04-07 17:52:20 +0200189 set_nport(&lsa->u.sa, htons(port_num));
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000190 return xconnect_stream(lsa);
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000191}
192
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000193static int pump_data_and_QUIT(int from, int to)
194{
195 /* copy the file */
196 if (bb_copyfd_eof(from, to) == -1) {
197 /* error msg is already printed by bb_copyfd_eof */
198 return EXIT_FAILURE;
199 }
200
201 /* close data connection */
202 close(from); /* don't know which one is that, so we close both */
203 close(to);
204
205 /* does server confirm that transfer is finished? */
206 if (ftpcmd(NULL, NULL) != 226) {
207 ftp_die(NULL);
208 }
209 ftpcmd("QUIT", NULL);
210
211 return EXIT_SUCCESS;
212}
213
Rob Landleyb1c3fbc2006-05-04 19:52:28 +0000214#if !ENABLE_FTPGET
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000215int ftp_receive(const char *local_path, char *server_path);
Rob Landleyb1c3fbc2006-05-04 19:52:28 +0000216#else
Denis Vlasenko7039a662006-10-08 17:54:47 +0000217static
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000218int ftp_receive(const char *local_path, char *server_path)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000219{
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000220 int fd_data;
Glenn L McGrath236e93d2003-12-20 05:43:34 +0000221 int fd_local = -1;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000222 off_t beg_range = 0;
223
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000224 /* connect to the data socket */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000225 fd_data = xconnect_ftpdata();
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000226
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000227 if (ftpcmd("SIZE", server_path) != 213) {
Rob Landleybc059bc2006-01-10 06:36:00 +0000228 do_continue = 0;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000229 }
230
Denis Vlasenko9f739442006-12-16 23:49:13 +0000231 if (LONE_DASH(local_path)) {
Eric Andersen70060d22004-03-27 10:02:48 +0000232 fd_local = STDOUT_FILENO;
Glenn L McGrath236e93d2003-12-20 05:43:34 +0000233 do_continue = 0;
234 }
235
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000236 if (do_continue) {
237 struct stat sbuf;
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000238 /* lstat would be wrong here! */
239 if (stat(local_path, &sbuf) < 0) {
240 bb_perror_msg_and_die("stat");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000241 }
242 if (sbuf.st_size > 0) {
243 beg_range = sbuf.st_size;
244 } else {
245 do_continue = 0;
246 }
247 }
248
249 if (do_continue) {
Denys Vlasenkoa3aa3e32009-12-11 12:36:10 +0100250 sprintf(buf, "REST %"OFF_FMT"u", beg_range);
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000251 if (ftpcmd(buf, NULL) != 350) {
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000252 do_continue = 0;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000253 }
254 }
255
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000256 if (ftpcmd("RETR", server_path) > 150) {
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000257 ftp_die("RETR");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000258 }
259
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000260 /* create local file _after_ we know that remote file exists */
Glenn L McGrath236e93d2003-12-20 05:43:34 +0000261 if (fd_local == -1) {
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000262 fd_local = xopen(local_path,
263 do_continue ? (O_APPEND | O_WRONLY)
264 : (O_CREAT | O_TRUNC | O_WRONLY)
265 );
Glenn L McGrath1643f412002-12-18 02:47:40 +0000266 }
267
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000268 return pump_data_and_QUIT(fd_data, fd_local);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000269}
270#endif
271
Rob Landleyb1c3fbc2006-05-04 19:52:28 +0000272#if !ENABLE_FTPPUT
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000273int ftp_send(const char *server_path, char *local_path);
Rob Landleyb1c3fbc2006-05-04 19:52:28 +0000274#else
Denis Vlasenko7039a662006-10-08 17:54:47 +0000275static
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000276int ftp_send(const char *server_path, char *local_path)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000277{
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000278 int fd_data;
279 int fd_local;
280 int response;
281
Denis Vlasenko6c615a62008-03-28 22:11:49 +0000282 /* connect to the data socket */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000283 fd_data = xconnect_ftpdata();
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000284
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000285 /* get the local file */
Denis Vlasenko9f739442006-12-16 23:49:13 +0000286 fd_local = STDIN_FILENO;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000287 if (NOT_LONE_DASH(local_path))
Rob Landleyd921b2e2006-08-03 15:41:12 +0000288 fd_local = xopen(local_path, O_RDONLY);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000289
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000290 response = ftpcmd("STOR", server_path);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000291 switch (response) {
292 case 125:
293 case 150:
294 break;
295 default:
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000296 ftp_die("STOR");
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000297 }
298
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000299 return pump_data_and_QUIT(fd_local, fd_data);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000300}
301#endif
302
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +0000303#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
Denis Vlasenko6ca409e2007-08-12 20:58:27 +0000304static const char ftpgetput_longopts[] ALIGN1 =
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +0000305 "continue\0" Required_argument "c"
306 "verbose\0" No_argument "v"
307 "username\0" Required_argument "u"
308 "password\0" Required_argument "p"
309 "port\0" Required_argument "P"
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000310 ;
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +0000311#endif
Glenn L McGrathb51eb262003-12-19 10:37:52 +0000312
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000313int ftpgetput_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000314int ftpgetput_main(int argc UNUSED_PARAM, char **argv)
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000315{
Denis Vlasenko562dc242007-01-03 21:55:50 +0000316 const char *port = "ftp";
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000317 /* socket to ftp server */
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000318
Denis Vlasenko562dc242007-01-03 21:55:50 +0000319#if ENABLE_FTPPUT && !ENABLE_FTPGET
320# define ftp_action ftp_send
321#elif ENABLE_FTPGET && !ENABLE_FTPPUT
322# define ftp_action ftp_receive
323#else
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000324 int (*ftp_action)(const char *, char *) = ftp_send;
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000325
Glenn L McGrath266c1f52003-12-20 03:19:27 +0000326 /* Check to see if the command is ftpget or ftput */
Denis Vlasenko562dc242007-01-03 21:55:50 +0000327 if (applet_name[3] == 'g') {
Bernhard Reutner-Fischere0387a62006-06-07 13:31:59 +0000328 ftp_action = ftp_receive;
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000329 }
Denis Vlasenko562dc242007-01-03 21:55:50 +0000330#endif
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000331
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000332 INIT_G();
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000333 /* Set default values */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000334 user = "anonymous";
335 password = "busybox@";
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000336
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000337 /*
338 * Decipher the command line
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000339 */
Denis Vlasenkoc61852a2006-11-29 11:09:43 +0000340#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +0000341 applet_long_options = ftpgetput_longopts;
Denis Vlasenkoc61852a2006-11-29 11:09:43 +0000342#endif
Vladimir Dronnikov1dacfbb2009-10-23 23:34:43 +0200343 opt_complementary = "-2:vv:cc"; /* must have 2 to 3 params; -v and -c count */
Denys Vlasenko60a94142011-05-13 20:57:01 +0200344 getopt32(argv, "cvu:p:P:", &user, &password, &port,
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000345 &verbose_flag, &do_continue);
Denis Vlasenko562dc242007-01-03 21:55:50 +0000346 argv += optind;
Glenn L McGrath236e93d2003-12-20 05:43:34 +0000347
Eric Andersen04d055f2003-11-03 21:20:18 +0000348 /* We want to do exactly _one_ DNS lookup, since some
349 * sites (i.e. ftp.us.debian.org) use round-robin DNS
350 * and we want to connect to only one IP... */
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000351 lsa = xhost2sockaddr(argv[0], bb_lookup_port(port, "tcp", 21));
Eric Andersen04d055f2003-11-03 21:20:18 +0000352 if (verbose_flag) {
Denis Vlasenko85629f02007-01-22 09:36:41 +0000353 printf("Connecting to %s (%s)\n", argv[0],
Denis Vlasenko0e7940a2008-03-29 07:37:42 +0000354 xmalloc_sockaddr2dotted(&lsa->u.sa));
Eric Andersen04d055f2003-11-03 21:20:18 +0000355 }
356
Denis Vlasenko7cb808e2008-03-29 07:40:35 +0000357 ftp_login();
Vladimir Dronnikov1dacfbb2009-10-23 23:34:43 +0200358 return ftp_action(argv[1], argv[2] ? argv[2] : argv[1]);
Glenn L McGrath02d7cbf2002-12-13 02:43:50 +0000359}