]> granicus.if.org Git - curl/commitdiff
ftp: prevent server from hanging on closed data connection
authorKamil Dudka <kdudka@redhat.com>
Wed, 27 Oct 2010 08:54:35 +0000 (10:54 +0200)
committerKamil Dudka <kdudka@redhat.com>
Fri, 29 Oct 2010 10:01:19 +0000 (12:01 +0200)
Some FTP servers (e.g. Pure-ftpd) end up hanging if we close the data
connection before transferring all the requested data.  If we send ABOR
in that case, it prevents the server from hanging.

Bug: https://bugzilla.redhat.com/643656
Reported by: Pasi Karkkainen, Patrick Monnerat

lib/ftp.c
tests/data/test1036
tests/data/test1057
tests/data/test110
tests/data/test122
tests/data/test135

index b5a4fd5be3d9d8717c8fd82113433adc721f91fd..679f2334cda45dff3094bf8e7e08b09215f77d72 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -3083,6 +3083,11 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
 #endif
 
   if(conn->sock[SECONDARYSOCKET] != CURL_SOCKET_BAD) {
+    if(!result && ftpc->dont_check)
+      /* prevent some FTP servers (namely Pure-ftpd) from hanging if we close
+       * the data channel before transferring all data */
+      result = Curl_pp_sendf(&ftpc->pp, "ABOR");
+
     if(conn->ssl[SECONDARYSOCKET].use) {
       /* The secondary socket is using SSL so we must close down that part
          first before we close the socket for real */
@@ -3097,7 +3102,7 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
     }
   }
 
-  if((ftp->transfer == FTPTRANSFER_BODY) && ftpc->ctl_valid &&
+  if(!result && (ftp->transfer == FTPTRANSFER_BODY) && ftpc->ctl_valid &&
      pp->pending_resp && !premature) {
     /*
      * Let's see what the server says about the transfer we just performed,
index b8ebc4fc0eb20d64a3abb873841c189fb73b26a0..a31cb458a654f3b4bdc591d93dc90cd4f0dc4311 100644 (file)
@@ -50,6 +50,7 @@ TYPE I
 SIZE 1036\r
 REST 20\r
 RETR 1036\r
+ABOR\r
 QUIT\r
 </protocol>
 <file name="log/curl1036.out">
index cfb88f2c5b5e96c51037d1dc117830122c621002..b4ef20c8da3d8369f38a234a31a2a4e54fd491f8 100644 (file)
@@ -45,6 +45,7 @@ TYPE I
 SIZE 1057\r
 REST 52\r
 RETR 1057\r
+ABOR\r
 QUIT\r
 </protocol>
 </verify>
index b63ba8a2dbc67310dcc502335e1e0b8924a6c15d..4a094e7e8b2ab3acd423c2c3902c039cadae182e 100644 (file)
@@ -46,6 +46,7 @@ TYPE I
 SIZE 110\r
 REST 20\r
 RETR 110\r
+ABOR\r
 QUIT\r
 </protocol>
 </verify>
index fb1dd05fc3f276abea70a83299e38da2cb059403..ac60672bb744a92d47b2c9d5853308861da12115 100644 (file)
@@ -39,6 +39,7 @@ EPSV
 PASV\r
 TYPE I\r
 SIZE 122\r
+ABOR\r
 QUIT\r
 </protocol>
 </verify>
index a051dba2074a650b7d4f9669a7b758d20bf28430..10eb0eacd1354bffe2e3df0ca534cfb530ceba8f 100644 (file)
@@ -47,6 +47,7 @@ TYPE I
 SIZE 135\r
 REST 4\r
 RETR 135\r
+ABOR\r
 QUIT\r
 </protocol>
 </verify>