Squid-2.2.STABLE3: Fall back on PORT Recover if ftp fails to establish PASV data connection. depends on squid-2.2.DEVEL3.ftp_broken_downloads.patch Index: squid/src/ftp.c diff -u squid/src/ftp.c:1.1.1.33.2.2 squid/src/ftp.c:1.1.1.33.2.3 --- squid/src/ftp.c:1.1.1.33.2.2 Wed May 19 23:38:43 1999 +++ squid/src/ftp.c Wed May 19 23:42:27 1999 @@ -1016,7 +1016,7 @@ ftpState->data.fd = -1; ftpState->size = -1; ftpState->mdtm = -1; - ftpState->flags.pasv_supported = 1; + ftpState->flags.pasv_supported = !fwd->flags.ftp_pasv_failed; ftpState->flags.rest_supported = 1; ftpState->fwd = fwd; comm_add_close_handler(fd, ftpStateFree, ftpState); @@ -1703,6 +1703,9 @@ FtpStateData *ftpState = data; debug(9, 3) ("ftpPasvCallback\n"); if (status != COMM_OK) { + debug(9, 2) ("ftpPasvCallback: failed to connect. Retrying without PASV.\n"); + ftpState->fwd->flags.dont_retry = 0; /* this is a retryable error */ + ftpState->fwd->flags.ftp_pasv_failed = 1; ftpFailed(ftpState, ERR_NONE); return; } @@ -1874,7 +1877,9 @@ { int code = ftpState->ctrl.replycode; debug(9, 3) ("This is ftpReadStor\n"); - if (code >= 100 && code < 200) { + if (code == 125 || (code == 150 && ftpState->data.host)) { + /* Begin data transfer */ + debug(9, 3) ("ftpReadStor: starting data transfer\n"); /* * Cancel the timeout on the Control socket, pumpStart will * establish one on the data socket. @@ -1883,15 +1888,17 @@ ftpPutStart(ftpState); debug(9, 3) ("ftpReadStor: writing data channel\n"); ftpState->state = WRITING_DATA; - } else if (code == 553) { - /* directory does not exist, have to create, sigh */ -#if WORK_IN_PROGRESS - ftpTraverseDirectory(ftpState); -#endif - ftpSendReply(ftpState); + } else if (code == 150) { + /* Accept data channel */ + debug(9, 3) ("ftpReadStor: accepting data channel\n"); + commSetSelect(ftpState->data.fd, + COMM_SELECT_READ, + ftpAcceptDataConnection, + ftpState, + 0); } else { - debug(9, 3) ("ftpReadStor: that's all folks\n"); - ftpSendReply(ftpState); + debug(9, 3) ("ftpReadStor: Unexpected reply code %s\n", code); + ftpFail(ftpState); } } @@ -2361,7 +2368,7 @@ err->ftp.reply = xstrdup(ftpState->ctrl.last_reply); errorAppendEntry(ftpState->entry, err); storeBufferFlush(ftpState->entry); - comm_close(ftpState->ctrl.fd); + ftpSendQuit(ftpState); } static void Index: squid/src/structs.h diff -u squid/src/structs.h:1.1.1.37.10.1 squid/src/structs.h:1.1.1.37.10.2 --- squid/src/structs.h:1.1.1.37.10.1 Wed May 19 23:38:45 1999 +++ squid/src/structs.h Wed May 19 23:42:29 1999 @@ -1600,6 +1600,7 @@ int n_tries; struct { unsigned int dont_retry:1; + unsigned int ftp_pasv_failed:1; } flags; };