]> sjero.net Git - wget/blobdiff - src/ftp-basic.c
[svn] Merge of fix for bugs 20341 and 20410.
[wget] / src / ftp-basic.c
index dd7d7b7addec75f8fe2da76b9a5b2caa9a661ea9..24026e194d89f0bff978e504ded1ab58189dea07 100644 (file)
@@ -1,11 +1,11 @@
 /* Basic FTP routines.
-   Copyright (C) 1996-2005 Free Software Foundation, Inc.
+   Copyright (C) 1996-2007 Free Software Foundation, Inc.
 
 This file is part of GNU Wget.
 
 GNU Wget is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
+the Free Software Foundation; either version 3 of the License, or
  (at your option) any later version.
 
 GNU Wget is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with Wget; if not, write to the Free Software Foundation, Inc.,
-51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+along with Wget.  If not, see <http://www.gnu.org/licenses/>.
 
 In addition, as a special exception, the Free Software Foundation
 gives permission to link the code of its release of Wget with the
@@ -962,33 +961,45 @@ ftp_list (int csock, const char *file)
   char *request, *respline;
   int nwritten;
   uerr_t err;
-
-  /* Send LIST request.  */
-  request = ftp_request ("LIST", file);
-  nwritten = fd_write (csock, request, strlen (request), -1);
-  if (nwritten < 0)
-    {
-      xfree (request);
-      return WRITEFAILED;
-    }
-  xfree (request);
-  /* Get appropriate respone.  */
-  err = ftp_response (csock, &respline);
-  if (err != FTPOK)
-    return err;
-  if (*respline == '5')
-    {
-      xfree (respline);
-      return FTPNSFOD;
-    }
-  if (*respline != '1')
-    {
-      xfree (respline);
-      return FTPRERR;
-    }
-  xfree (respline);
-  /* All OK.  */
-  return FTPOK;
+  bool ok = false;
+  int i = 0;
+  /* Try `LIST -a' first and revert to `LIST' in case of failure.  */
+  const char *list_commands[] = { "LIST -a", 
+                                  "LIST" };
+
+  do {
+    /* Send request.  */
+    request = ftp_request (list_commands[i], file);
+    nwritten = fd_write (csock, request, strlen (request), -1);
+    if (nwritten < 0)
+      {
+        xfree (request);
+        return WRITEFAILED;
+      }
+    xfree (request);
+    /* Get appropriate response.  */
+    err = ftp_response (csock, &respline);
+    if (err == FTPOK)
+      {
+        if (*respline == '5')
+          {
+            err = FTPNSFOD;
+          }
+       else if (*respline == '1')
+          {
+            err = FTPOK;
+            ok = true;
+          }
+        else 
+          {
+           err = FTPRERR;
+          }
+        xfree (respline);
+      }
+    ++i;
+  } while (i < countof (list_commands) && !ok);
+  
+  return err;
 }
 
 /* Sends the SYST command to the server. */
@@ -1026,7 +1037,9 @@ ftp_syst (int csock, enum stype *server_type)
      first word of the server response)?  */
   request = strtok (NULL, " ");
 
-  if (!strcasecmp (request, "VMS"))
+  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;