]> sjero.net Git - wget/blobdiff - src/ftp.c
[svn] Update FSF's address and copyright years.
[wget] / src / ftp.c
index e8e9a5a4a34f196e41b06d2c9f91a9f447320c7f..3c978620c6045243adfde68589495d292ecb2e14 100644 (file)
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -1,6 +1,5 @@
 /* File Transfer Protocol support.
-   Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001
-   Free Software Foundation, Inc.
+   Copyright (C) 1996-2005 Free Software Foundation, Inc.
 
 This file is part of GNU Wget.
 
@@ -15,8 +14,8 @@ 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+along with Wget; if not, write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
 In addition, as a special exception, the Free Software Foundation
 gives permission to link the code of its release of Wget with the
@@ -50,16 +49,9 @@ so, delete this exception statement from your version.  */
 #include "convert.h"           /* for downloaded_file */
 #include "recur.h"             /* for INFINITE_RECURSION */
 
-extern LARGE_INT total_downloaded_bytes;
-
 /* File where the "ls -al" listing will be saved.  */
 #define LIST_FILENAME ".listing"
 
-extern char ftp_last_respline[];
-
-extern FILE *output_stream;
-extern bool output_stream_regular;
-
 typedef struct
 {
   int st;                      /* connection status */
@@ -212,20 +204,20 @@ ftp_do_port (int csock, int *local_sock)
 #endif
 
 static void
-print_length (wgint size, wgint start, int authoritative)
+print_length (wgint size, wgint start, bool authoritative)
 {
-  logprintf (LOG_VERBOSE, _("Length: %s"), with_thousand_seps (size));
+  logprintf (LOG_VERBOSE, _("Length: %s"), number_to_static_string (size));
   if (size >= 1024)
     logprintf (LOG_VERBOSE, " (%s)", human_readable (size));
   if (start > 0)
     {
       if (start >= 1024)
        logprintf (LOG_VERBOSE, _(", %s (%s) remaining"),
-                  with_thousand_seps (size - start),
+                  number_to_static_string (size - start),
                   human_readable (size - start));
       else
        logprintf (LOG_VERBOSE, _(", %s remaining"),
-                  with_thousand_seps (size - start));
+                  number_to_static_string (size - start));
     }
   logputs (LOG_VERBOSE, !authoritative ? _(" (unauthoritative)\n") : "\n");
 }
@@ -240,7 +232,8 @@ getftp (struct url *u, wgint *len, wgint restval, ccon *con)
   uerr_t err = RETROK;         /* appease the compiler */
   FILE *fp;
   char *user, *passwd, *respline;
-  char *tms, *tmrate;
+  char *tms;
+  const char *tmrate;
   int cmd = con->cmd;
   bool pasv_mode_open = false;
   wgint expected_bytes = 0;
@@ -585,7 +578,7 @@ Error in server response, closing control connection.\n"));
   else /* do not CWD */
     logputs (LOG_VERBOSE, _("==> CWD not required.\n"));
 
-  if ((cmd & DO_RETR) && restval && *len == 0)
+  if ((cmd & DO_RETR) && *len == 0)
     {
       if (opt.verbose)
        {
@@ -598,7 +591,7 @@ Error in server response, closing control connection.\n"));
       switch (err)
        {
        case FTPRERR:
-       case FTPSRVERR :
+       case FTPSRVERR:
          logputs (LOG_VERBOSE, "\n");
          logputs (LOG_NOTQUIET, _("\
 Error in server response, closing control connection.\n"));
@@ -612,7 +605,8 @@ Error in server response, closing control connection.\n"));
          abort ();
        }
        if (!opt.server_response)
-         logputs (LOG_VERBOSE, _("done.\n"));
+         logprintf (LOG_VERBOSE, *len ? "%s\n" : _("done.\n"),
+                    number_to_static_string (*len));
     }
 
   /* If anything is to be retrieved, PORT (or PASV) must be sent.  */
@@ -656,8 +650,7 @@ Error in server response, closing control connection.\n"));
          if (err==FTPOK)
            {
              DEBUGP (("trying to connect to %s port %d\n", 
-                     pretty_print_address (&passive_addr),
-                     passive_port));
+                     print_address (&passive_addr), passive_port));
              dtsock = connect_to_ip (&passive_addr, passive_port, NULL);
              if (dtsock < 0)
                {
@@ -665,7 +658,7 @@ Error in server response, closing control connection.\n"));
                  fd_close (csock);
                  con->csock = -1;
                  logprintf (LOG_VERBOSE, _("couldn't connect to %s port %d: %s\n"),
-                            pretty_print_address (&passive_addr), passive_port,
+                            print_address (&passive_addr), passive_port,
                             strerror (save_errno));
                  return (retryable_socket_connect_error (save_errno)
                          ? CONERROR : CONIMPOSSIBLE);
@@ -958,11 +951,11 @@ Error in server response, closing control connection.\n"));
 
   if (*len)
     {
-      print_length (*len, restval, 1);
+      print_length (*len, restval, true);
       expected_bytes = *len;   /* for get_contents/show_progress */
     }
   else if (expected_bytes)
-    print_length (expected_bytes, restval, 0);
+    print_length (expected_bytes, restval, false);
 
   /* Get the contents of the document.  */
   flags = 0;
@@ -975,7 +968,9 @@ Error in server response, closing control connection.\n"));
                      restval, &rd_size, len, &con->dltime, flags);
 
   tms = time_str (NULL);
-  tmrate = retr_rate (rd_size, con->dltime, 0);
+  tmrate = retr_rate (rd_size, con->dltime);
+  total_download_time += con->dltime;
+
   /* Close data connection socket.  */
   fd_close (dtsock);
   fd_close (local_sock);
@@ -1071,6 +1066,9 @@ Error in server response, closing control connection.\n"));
             no-buffering on opt.lfile.  */
          while ((line = read_whole_line (fp)) != NULL)
            {
+             char *p = strchr (line, '\0');
+             while (p > line && (p[-1] == '\n' || p[-1] == '\r'))
+               *--p = '\0';
              logprintf (LOG_ALWAYS, "%s\n", escnonprint (line));
              xfree (line);
            }
@@ -1092,7 +1090,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
   int count, orig_lp;
   wgint restval, len = 0;
   char *tms, *locf;
-  char *tmrate = NULL;
+  const char *tmrate = NULL;
   uerr_t err;
   struct_stat st;
 
@@ -1228,7 +1226,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
        }
       tms = time_str (NULL);
       if (!opt.spider)
-        tmrate = retr_rate (len - restval, con->dltime, 0);
+        tmrate = retr_rate (len - restval, con->dltime);
 
       /* If we get out of the switch above without continue'ing, we've
         successfully downloaded a file.  Remember this fact. */
@@ -1306,7 +1304,7 @@ Removing file due to --delete-after in ftp_loop_internal():\n"));
 
 /* Return the directory listing in a reusable format.  The directory
    is specifed in u->dir.  */
-uerr_t
+static uerr_t
 ftp_get_listing (struct url *u, ccon *con, struct fileinfo **f)
 {
   uerr_t err;