]> sjero.net Git - wget/blobdiff - src/ftp.c
Add --unlink.
[wget] / src / ftp.c
index d3f6b18ba36eacd62e6c5fec908a74902f7da524..cba545002d9039a936bfd18da3dcb0852387374d 100644 (file)
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -1173,7 +1173,22 @@ Error in server response, closing control connection.\n"));
         }
       else if (opt.noclobber || opt.always_rest || opt.timestamping || opt.dirstruct
                || opt.output_document)
-        {
+        {        
+         if (opt.unlink && file_exists_p (con->target))
+           {
+             int res = unlink (con->target);
+             if (res < 0)
+               {
+                 logprintf (LOG_NOTQUIET, "%s: %s\n", con->target,
+                            strerror (errno));
+                 fd_close (csock);
+                 con->csock = -1;
+                 fd_close (dtsock);
+                 fd_close (local_sock);
+                 return UNLINKERR;
+               }
+           }
+
 #ifdef __VMS
           int open_id;
 
@@ -1484,6 +1499,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con, char **local_fi
         {
         case HOSTERR: case CONIMPOSSIBLE: case FWRITEERR: case FOPENERR:
         case FTPNSFOD: case FTPLOGINC: case FTPNOPASV: case CONTNOTSUPPORTED:
+        case UNLINKERR:
           /* Fatal errors, give up.  */
           return err;
         case CONSOCKERR: case CONERROR: case FTPSRVERR: case FTPRERR: