1
1
/* Basic FTP routines.
2
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3
2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
2
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3
2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5
5
This file is part of GNU Wget.
80
78
if (opt.server_response)
81
logprintf (LOG_NOTQUIET, "%s\n", escnonprint (line));
79
logprintf (LOG_NOTQUIET, "%s\n",
80
quotearg_style (escape_quoting_style, line));
83
DEBUGP (("%s\n", escnonprint (line)));
82
DEBUGP (("%s\n", quotearg_style (escape_quoting_style, line)));
85
84
/* The last line of output is the one that begins with "ddd ". */
86
if (ISDIGIT (line[0]) && ISDIGIT (line[1]) && ISDIGIT (line[2])
85
if (c_isdigit (line[0]) && c_isdigit (line[1]) && c_isdigit (line[2])
89
88
strncpy (ftp_last_respline, line, sizeof (ftp_last_respline));
118
117
if (*p == '\r' || *p == '\n')
120
119
DEBUGP (("\nDetected newlines in %s \"%s\"; changing to %s \"%s\"\n",
121
command, escnonprint (value), command, escnonprint (defanged)));
120
command, quotearg_style (escape_quoting_style, value),
121
command, quotearg_style (escape_quoting_style, defanged)));
122
122
/* Make VALUE point to the defanged copy of the string. */
123
123
value = defanged;
331
331
assert (buflen >= 21 * 4);
333
333
/* Construct the argument of LPRT (of the form af,n,h1,h2,...,hn,p1,p2). */
334
switch (addr->family)
334
switch (addr->family)
337
snprintf (buf, buflen, "%d,%d,%d,%d,%d,%d,%d,%d,%d", 4, 4,
337
snprintf (buf, buflen, "%d,%d,%d,%d,%d,%d,%d,%d,%d", 4, 4,
338
338
ptr[0], ptr[1], ptr[2], ptr[3], 2,
339
339
(port & 0xff00) >> 8, port & 0xff);
342
342
snprintf (buf, buflen,
343
343
"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
345
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7],
345
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7],
346
346
ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15],
347
347
2, (port & 0xff00) >> 8, port & 0xff);
413
ip_address_to_eprt_repr (const ip_address *addr, int port, char *buf,
413
ip_address_to_eprt_repr (const ip_address *addr, int port, char *buf,
418
/* buf must contain the argument of EPRT (of the form |af|addr|port|).
419
* 4 chars for the | separators, INET6_ADDRSTRLEN chars for addr
418
/* buf must contain the argument of EPRT (of the form |af|addr|port|).
419
* 4 chars for the | separators, INET6_ADDRSTRLEN chars for addr
420
420
* 1 char for af (1-2) and 5 chars for port (0-65535) */
421
assert (buflen >= 4 + INET6_ADDRSTRLEN + 1 + 5);
421
assert (buflen >= 4 + INET6_ADDRSTRLEN + 1 + 5);
423
423
/* Construct the argument of EPRT (of the form |af|addr|port|). */
424
424
afnum = (addr->family == AF_INET ? 1 : 2);
440
/* Must contain the argument of EPRT (of the form |af|addr|port|).
441
* 4 chars for the | separators, INET6_ADDRSTRLEN chars for addr
440
/* Must contain the argument of EPRT (of the form |af|addr|port|).
441
* 4 chars for the | separators, INET6_ADDRSTRLEN chars for addr
442
442
* 1 char for af (1-2) and 5 chars for port (0-65535) */
443
443
char bytes[4 + INET6_ADDRSTRLEN + 1 + 5 + 1];
588
588
xfree (respline);
589
589
return FTPNOPASV;
592
592
/* Parse the response. */
594
for (s += 4; *s && !ISDIGIT (*s); s++)
594
for (s += 4; *s && !c_isdigit (*s); s++)
597
597
return FTPINVPASV;
599
599
/* First, get the address family */
601
for (; ISDIGIT (*s); s++)
601
for (; c_isdigit (*s); s++)
602
602
af = (*s - '0') + 10 * af;
604
604
if (af != 4 && af != 6)
958
958
/* Sends the LIST command to the server. If FILE is NULL, send just
959
959
`LIST' (no space). */
961
ftp_list (int csock, const char *file)
961
ftp_list (int csock, const char *file, enum stype rs)
963
963
char *request, *respline;
968
968
/* Try `LIST -a' first and revert to `LIST' in case of failure. */
969
const char *list_commands[] = { "LIST -a",
969
const char *list_commands[] = { "LIST -a",
972
/* 2008-01-29 SMS. For a VMS FTP server, where "LIST -a" may not
973
fail, but will never do what is desired here, skip directly to the
974
simple "LIST" command (assumed to be the last one in the list).
977
i = countof (list_commands)- 1;
973
980
/* Send request. */
974
981
request = ftp_request (list_commands[i], file);