diff options
author | Daniel Stenberg <daniel@haxx.se> | 2006-04-18 23:14:30 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2006-04-18 23:14:30 +0000 |
commit | e532b196ccc671a14b9ab9bc18860b2656e5ea42 (patch) | |
tree | 70ff3a69ca07beac09da5d4df8c7dc426545090d /lib/ftp.c | |
parent | 0f5232280cc1e38127be89bc97047688a7e70810 (diff) | |
download | curl-e532b196ccc671a14b9ab9bc18860b2656e5ea42.tar.gz |
Robson Braga Araujo provided a patch that makes libcurl less eager to close
the control connection when using FTP, for example when you remove an easy
handle from a multi stack.
Diffstat (limited to 'lib/ftp.c')
-rw-r--r-- | lib/ftp.c | 76 |
1 files changed, 37 insertions, 39 deletions
@@ -2912,42 +2912,6 @@ CURLcode Curl_ftp_done(struct connectdata *conn, CURLcode status) /* free the dir tree and file parts */ freedirs(ftp); - ftp->ctl_valid = FALSE; - - if(data->set.upload) { - if((-1 != data->set.infilesize) && - (data->set.infilesize != *ftp->bytecountp) && - !data->set.crlf && - !ftp->no_transfer) { - failf(data, "Uploaded unaligned file size (%" FORMAT_OFF_T - " out of %" FORMAT_OFF_T " bytes)", - *ftp->bytecountp, data->set.infilesize); - conn->bits.close = TRUE; /* close this connection since we don't - know what state this error leaves us in */ - return CURLE_PARTIAL_FILE; - } - } - else { - if((-1 != conn->size) && (conn->size != *ftp->bytecountp) && - (conn->maxdownload != *ftp->bytecountp)) { - failf(data, "Received only partial file: %" FORMAT_OFF_T " bytes", - *ftp->bytecountp); - conn->bits.close = TRUE; /* close this connection since we don't - know what state this error leaves us in */ - return CURLE_PARTIAL_FILE; - } - else if(!ftp->dont_check && - !*ftp->bytecountp && - (conn->size>0)) { - /* We consider this an error, but there's no true FTP error received - why we need to continue to "read out" the server response too. - We don't want to leave a "waiting" server reply if we'll get told - to make a second request on this same connection! */ - failf(data, "No data was received!"); - result = CURLE_FTP_COULDNT_RETR_FILE; - } - } - switch(status) { case CURLE_BAD_DOWNLOAD_RESUME: case CURLE_FTP_WEIRD_PASV_REPLY: @@ -2981,19 +2945,23 @@ CURLcode Curl_ftp_done(struct connectdata *conn, CURLcode status) conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD; if(!ftp->no_transfer && !status) { - /* Let's see what the server says about the transfer we just performed, + /* + * Let's see what the server says about the transfer we just performed, * but lower the timeout as sometimes this connection has died while the * data has been transfered. This happens when doing through NATs etc that * abandon old silent connections. */ + long old_time = ftp->response_time; + ftp->response_time = 60; /* give it only a minute for now */ result = Curl_GetFTPResponse(&nread, conn, &ftpcode); - ftp->response_time = 3600; /* set this back to one hour waits */ + ftp->response_time = old_time; /* set this back to previous value */ if(!nread && (CURLE_OPERATION_TIMEDOUT == result)) { failf(data, "control connection looks dead"); + ftp->ctl_valid = FALSE; /* mark control connection as bad */ return result; } @@ -3004,11 +2972,41 @@ CURLcode Curl_ftp_done(struct connectdata *conn, CURLcode status) /* 226 Transfer complete, 250 Requested file action okay, completed. */ if((ftpcode != 226) && (ftpcode != 250)) { failf(data, "server did not report OK, got %d", ftpcode); - return CURLE_FTP_WRITE_ERROR; + result = CURLE_PARTIAL_FILE; } } } + if(result) + /* the response code from the transfer showed an error already so no + use checking further */ + ; + else if(data->set.upload) { + if((-1 != data->set.infilesize) && + (data->set.infilesize != *ftp->bytecountp) && + !data->set.crlf && + !ftp->no_transfer) { + failf(data, "Uploaded unaligned file size (%" FORMAT_OFF_T + " out of %" FORMAT_OFF_T " bytes)", + *ftp->bytecountp, data->set.infilesize); + result = CURLE_PARTIAL_FILE; + } + } + else { + if((-1 != conn->size) && (conn->size != *ftp->bytecountp) && + (conn->maxdownload != *ftp->bytecountp)) { + failf(data, "Received only partial file: %" FORMAT_OFF_T " bytes", + *ftp->bytecountp); + result = CURLE_PARTIAL_FILE; + } + else if(!ftp->dont_check && + !*ftp->bytecountp && + (conn->size>0)) { + failf(data, "No data was received!"); + result = CURLE_FTP_COULDNT_RETR_FILE; + } + } + /* clear these for next connection */ ftp->no_transfer = FALSE; ftp->dont_check = FALSE; |