]> sjero.net Git - wget/blobdiff - src/ftp.c
Fix symlinks resume via FTP.
[wget] / src / ftp.c
index c5ac83032aa596ad659bd9fa3b384db5669618a7..42b0671e1c00510a5fbf426c46706ccffe0ceb73 100644 (file)
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -63,8 +63,6 @@ as that of the covered work.  */
 #define LIST_FILENAME ".listing"
 #endif
 
-#define max(a, b) ((a > b) ? (a) : (b))
-
 typedef struct
 {
   int st;                       /* connection status */
@@ -254,6 +252,7 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
   int cmd = con->cmd;
   bool pasv_mode_open = false;
   wgint expected_bytes = 0;
+  bool got_expected_bytes = false;
   bool rest_failed = false;
   int flags;
   wgint rd_size;
@@ -757,6 +756,7 @@ Error in server response, closing control connection.\n"));
           con->csock = -1;
           return err;
         case FTPOK:
+          got_expected_bytes = true;
           /* Everything is OK.  */
           break;
         default:
@@ -767,6 +767,16 @@ Error in server response, closing control connection.\n"));
                      number_to_static_string (expected_bytes));
     }
 
+  if (cmd & DO_RETR && restval > 0 && restval == expected_bytes)
+    {
+      /* Server confirms that file has length restval. We should stop now.
+         Some servers (f.e. NcFTPd) return error when receive REST 0 */
+      logputs (LOG_VERBOSE, _("File has already been retrieved.\n"));
+      fd_close (csock);
+      con->csock = -1;
+      return RETRFINISHED;
+    }
+
   /* If anything is to be retrieved, PORT (or PASV) must be sent.  */
   if (cmd & (DO_LIST | DO_RETR))
     {
@@ -1022,8 +1032,8 @@ Error in server response, closing control connection.\n"));
       if (!opt.server_response)
         logputs (LOG_VERBOSE, _("done.\n"));
 
-      expected_bytes = max (ftp_expected_bytes (ftp_last_respline),
-                            expected_bytes);
+      if (! got_expected_bytes)
+        expected_bytes = ftp_expected_bytes (ftp_last_respline);
     } /* do retrieve */
 
   if (cmd & DO_LIST)
@@ -1069,8 +1079,9 @@ Error in server response, closing control connection.\n"));
         }
       if (!opt.server_response)
         logputs (LOG_VERBOSE, _("done.\n"));
-      expected_bytes = max (ftp_expected_bytes (ftp_last_respline),
-                            expected_bytes);
+
+      if (! got_expected_bytes)
+        expected_bytes = ftp_expected_bytes (ftp_last_respline);
     } /* cmd & DO_LIST */
 
   if (!(cmd & (DO_LIST | DO_RETR)) || (opt.spider && !(cmd & DO_LIST)))
@@ -1458,7 +1469,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con, char **local_fi
           xfree (hurl);
         }
       /* Send getftp the proper length, if fileinfo was provided.  */
-      if (f)
+      if (f && f->type != FT_SYMLINK)
         len = f->size;
       else
         len = 0;