/* Basic FTP routines.
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+ 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
+ Inc.
This file is part of GNU Wget.
#include <errno.h>
#include <string.h>
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
+#include <unistd.h>
#include "utils.h"
#include "connect.h"
#include "host.h"
for (s += 4; *s && !c_isdigit (*s); s++)
;
if (!*s)
- return FTPINVPASV;
+ {
+ xfree (respline);
+ return FTPINVPASV;
+ }
for (i = 0; i < 6; i++)
{
tmp[i] = 0;
for (s += 4; *s && !c_isdigit (*s); s++)
;
if (!*s)
- return FTPINVPASV;
+ {
+ xfree (respline);
+ return FTPINVPASV;
+ }
/* First, get the address family */
af = 0;
DEBUGP(("respline is %s\n", respline));
- /* Parse the response. */
- s = respline;
-
/* Skip the useless stuff and get what's inside the parentheses */
start = strchr (respline, '(');
if (start == NULL)
return FTPINVPASV;
}
- if (*s++ != ')')
+ if (*s != ')')
{
xfree (respline);
return FTPINVPASV;
/* Sends the LIST command to the server. If FILE is NULL, send just
`LIST' (no space). */
uerr_t
-ftp_list (int csock, const char *file, enum stype rs)
+ftp_list (int csock, const char *file, bool avoid_list_a, bool avoid_list,
+ bool *list_a_used)
{
char *request, *respline;
int nwritten;
uerr_t err;
bool ok = false;
size_t i = 0;
- /* Try `LIST -a' first and revert to `LIST' in case of failure. */
+
+ *list_a_used = false;
+
+ /* 2013-10-12 Andrea Urbani (matfanjol)
+ For more information about LIST and "LIST -a" please look at ftp.c,
+ function getftp, text "__LIST_A_EXPLANATION__".
+
+ If somebody changes the following commands, please, checks also the
+ later "i" variable. */
const char *list_commands[] = { "LIST -a",
"LIST" };
- /* 2008-01-29 SMS. For a VMS FTP server, where "LIST -a" may not
- fail, but will never do what is desired here, skip directly to the
- simple "LIST" command (assumed to be the last one in the list).
- */
- if (rs == ST_VMS)
- i = countof (list_commands)- 1;
+ if (avoid_list_a)
+ {
+ i = countof (list_commands)- 1;
+ DEBUGP (("(skipping \"LIST -a\")"));
+ }
+
do {
/* Send request. */
{
err = FTPOK;
ok = true;
+ /* Which list command was used? */
+ *list_a_used = (i == 0);
}
else
{
xfree (respline);
}
++i;
+ if ((avoid_list) && (i == 1))
+ {
+ /* I skip LIST */
+ ++i;
+ DEBUGP (("(skipping \"LIST\")"));
+ }
} while (i < countof (list_commands) && !ok);
return err;
/* Sends the SYST command to the server. */
uerr_t
-ftp_syst (int csock, enum stype *server_type)
+ftp_syst (int csock, enum stype *server_type, enum ustype *unix_type)
{
char *request, *respline;
int nwritten;
first word of the server response)? */
request = strtok (NULL, " ");
+ *unix_type = UST_OTHER;
+
if (request == NULL)
*server_type = ST_OTHER;
else if (!strcasecmp (request, "VMS"))
*server_type = ST_VMS;
else if (!strcasecmp (request, "UNIX"))
- *server_type = ST_UNIX;
+ {
+ *server_type = ST_UNIX;
+ /* 2013-10-17 Andrea Urbani (matfanjol)
+ I check more in depth the system type */
+ if (!strncasecmp (ftp_last_respline, "215 UNIX Type: L8", 17))
+ *unix_type = UST_TYPE_L8;
+ else if (!strncasecmp (ftp_last_respline,
+ "215 UNIX MultiNet Unix Emulation V5.3(93)", 41))
+ *unix_type = UST_MULTINET;
+ }
else if (!strcasecmp (request, "WINDOWS_NT")
|| !strcasecmp (request, "WINDOWS2000"))
*server_type = ST_WINNT;