From: Daniel Stenberg Date: Fri, 27 Feb 2004 07:08:37 +0000 (+0000) Subject: Joe Halpin made the FTP code send 'QUIT' on the control connection before X-Git-Tag: curl-7_11_1~196 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77268e064905931536498a87213ebece96a64f9b;p=thirdparty%2Fcurl.git Joe Halpin made the FTP code send 'QUIT' on the control connection before it disconnects the TCP connection, like a good ftp client should! --- diff --git a/lib/ftp.c b/lib/ftp.c index d6c161f169..0622e7edb2 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -2288,12 +2288,14 @@ CURLcode ftp_perform(struct connectdata *conn, * parts etc as a wrapper to the actual DO function (ftp_perform). * * The input argument is already checked for validity. + * + * ftp->ctl_valid starts out as FALSE, and gets set to TRUE if we reach the + * end of the function. */ CURLcode Curl_ftp(struct connectdata *conn) { CURLcode retcode=CURLE_OK; bool connected=0; - struct SessionHandle *data = conn->data; struct FTP *ftp; @@ -2304,6 +2306,7 @@ CURLcode Curl_ftp(struct connectdata *conn) /* the ftp struct is already inited in ftp_connect() */ ftp = conn->proto.ftp; + ftp->ctl_valid = FALSE; conn->size = -1; /* make sure this is unknown at this point */ Curl_pgrsSetUploadCounter(data, 0); @@ -2386,6 +2389,7 @@ CURLcode Curl_ftp(struct connectdata *conn) else freedirs(ftp); + ftp->ctl_valid = TRUE; return retcode; } @@ -2452,11 +2456,13 @@ CURLcode Curl_ftp_quit(struct connectdata *conn) { ssize_t nread; int ftpcode; - CURLcode ret; + CURLcode ret = CURLE_OK; - ret = Curl_ftpsendf(conn, "%s", "QUIT"); - if(CURLE_OK == ret) - ret = Curl_GetFTPResponse(&nread, conn, &ftpcode); + if(conn->proto.ftp->ctl_valid) { + ret = Curl_ftpsendf(conn, "%s", "QUIT"); + if(CURLE_OK == ret) + ret = Curl_GetFTPResponse(&nread, conn, &ftpcode); + } return ret; } @@ -2472,15 +2478,14 @@ CURLcode Curl_ftp_disconnect(struct connectdata *conn) { struct FTP *ftp= conn->proto.ftp; -#if 0 /* We cannot send quit unconditionally. If this connection is stale or bad in any way, sending quit and waiting around here will make the disconnect wait in vain and cause more problems than we need to. - - Until fixed, we keep this #if 0'ed. To be fixed in 7.11.1. Stay tuned. + + Curl_ftp_quit() will check the state of ftp->ctl_valid. If it's ok it + will try to send the QUIT command, otherwise it will just return. */ (void)Curl_ftp_quit(conn); /* ignore errors on the QUIT */ -#endif /* The FTP session may or may not have been allocated/setup at this point! */ if(ftp) { diff --git a/lib/urldata.h b/lib/urldata.h index 33a3fe120b..821a0c37ea 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -258,6 +258,10 @@ struct FTP { long response_time; /* When no timeout is given, this is the amount of seconds we await for an FTP response. Initialized in Curl_ftp_connect() */ + bool ctl_valid; /* Tells Curl_ftp_quit() whether or not to do + anything. If the connection has timed out or + been closed, this should be FALSE when it gets + to Curl_ftp_quit() */ }; /**************************************************************************** diff --git a/tests/data/test100 b/tests/data/test100 index 8fbb1714e9..aad4601614 100644 --- a/tests/data/test100 +++ b/tests/data/test100 @@ -43,5 +43,6 @@ PWD EPSV TYPE A LIST +QUIT diff --git a/tests/data/test101 b/tests/data/test101 index eabc6e2efc..67f5968e45 100644 --- a/tests/data/test101 +++ b/tests/data/test101 @@ -43,5 +43,6 @@ PWD PORT 127,0,0,1,243,212 TYPE A LIST +QUIT diff --git a/tests/data/test102 b/tests/data/test102 index a124581fd8..ebb58e898c 100644 --- a/tests/data/test102 +++ b/tests/data/test102 @@ -38,5 +38,6 @@ PASV TYPE I SIZE 102 RETR 102 +QUIT diff --git a/tests/data/test103 b/tests/data/test103 index e463913186..d8aa339c34 100644 --- a/tests/data/test103 +++ b/tests/data/test103 @@ -40,5 +40,6 @@ PORT 127,0,0,1,246,33 TYPE I SIZE 103 RETR 103 +QUIT diff --git a/tests/data/test104 b/tests/data/test104 index 4a72caec72..b0b9c45efc 100644 --- a/tests/data/test104 +++ b/tests/data/test104 @@ -30,5 +30,6 @@ MDTM 103 TYPE I SIZE 103 REST 0 +QUIT diff --git a/tests/data/test105 b/tests/data/test105 index b077ecc750..0245592e3f 100644 --- a/tests/data/test105 +++ b/tests/data/test105 @@ -38,5 +38,6 @@ PASV TYPE A SIZE 103 RETR 103 +QUIT diff --git a/tests/data/test106 b/tests/data/test106 index c6a66cd1b4..359af4f2ea 100644 --- a/tests/data/test106 +++ b/tests/data/test106 @@ -35,5 +35,6 @@ EPSV TYPE A SIZE 106 RETR 106 +QUIT diff --git a/tests/data/test107 b/tests/data/test107 index bb69f16b79..c97dbb9a46 100644 --- a/tests/data/test107 +++ b/tests/data/test107 @@ -37,5 +37,6 @@ PWD EPSV TYPE I STOR 107 +QUIT diff --git a/tests/data/test108 b/tests/data/test108 index 27c5c6d237..7ab7b4791d 100644 --- a/tests/data/test108 +++ b/tests/data/test108 @@ -38,6 +38,7 @@ CWD RETR PORT 127,0,0,1,5,109 TYPE I STOR 108 +QUIT Moooooooooooo diff --git a/tests/data/test109 b/tests/data/test109 index 4aad721236..1362d5b317 100644 --- a/tests/data/test109 +++ b/tests/data/test109 @@ -32,6 +32,7 @@ PWD EPSV TYPE I APPE 109 +QUIT Moooooooooooo diff --git a/tests/data/test110 b/tests/data/test110 index 4014daa82c..38f40c7b7c 100644 --- a/tests/data/test110 +++ b/tests/data/test110 @@ -39,5 +39,6 @@ TYPE I SIZE 110 REST 20 RETR 110 +QUIT diff --git a/tests/data/test111 b/tests/data/test111 index 78b6141af0..0664bfd770 100644 --- a/tests/data/test111 +++ b/tests/data/test111 @@ -32,5 +32,6 @@ PWD EPSV TYPE I SIZE 111 +QUIT diff --git a/tests/data/test112 b/tests/data/test112 index e519d67565..fe3dd52cbb 100644 --- a/tests/data/test112 +++ b/tests/data/test112 @@ -31,6 +31,7 @@ PWD EPSV TYPE I APPE 112 +QUIT gonna upload diff --git a/tests/data/test115 b/tests/data/test115 index 204b0ccd98..03a5caf1de 100644 --- a/tests/data/test115 +++ b/tests/data/test115 @@ -30,5 +30,6 @@ PASS curl_by_daniel@haxx.se PWD EPSV PASV +QUIT diff --git a/tests/data/test116 b/tests/data/test116 index 0bc8620c8a..57ad11ae2b 100644 --- a/tests/data/test116 +++ b/tests/data/test116 @@ -32,5 +32,6 @@ REPLY PORT 314 bluah you f00l! USER anonymous PASS curl_by_daniel@haxx.se PWD +QUIT diff --git a/tests/data/test117 b/tests/data/test117 index 428cbee9da..43a10958e6 100644 --- a/tests/data/test117 +++ b/tests/data/test117 @@ -31,5 +31,6 @@ PWD EPSV PASV TYPE I +QUIT diff --git a/tests/data/test118 b/tests/data/test118 index b97c0c9615..0cce25cb84 100644 --- a/tests/data/test118 +++ b/tests/data/test118 @@ -33,5 +33,6 @@ PASV TYPE I SIZE 118 RETR 118 +QUIT diff --git a/tests/data/test119 b/tests/data/test119 index 2e53a82b2c..96d30d7e7d 100644 --- a/tests/data/test119 +++ b/tests/data/test119 @@ -35,5 +35,6 @@ PWD TYPE I SIZE 119 RETR 119 +QUIT diff --git a/tests/data/test120 b/tests/data/test120 index 2fcf015390..ebc5691cd8 100644 --- a/tests/data/test120 +++ b/tests/data/test120 @@ -38,5 +38,6 @@ TYPE I SIZE 120 RETR 120 DELE file +QUIT diff --git a/tests/data/test121 b/tests/data/test121 index 64d26f9e29..427d88ba7a 100644 --- a/tests/data/test121 +++ b/tests/data/test121 @@ -35,5 +35,6 @@ TYPE I SIZE 121 RETR 121 DELE after_transfer +QUIT diff --git a/tests/data/test122 b/tests/data/test122 index 3e385502aa..5b7bafe758 100644 --- a/tests/data/test122 +++ b/tests/data/test122 @@ -31,5 +31,6 @@ EPSV PASV TYPE I SIZE 122 +QUIT diff --git a/tests/data/test123 b/tests/data/test123 index 066d709605..3825360b07 100644 --- a/tests/data/test123 +++ b/tests/data/test123 @@ -26,5 +26,6 @@ PASS curl_by_daniel@haxx.se PWD EPSV TYPE I +QUIT diff --git a/tests/data/test124 b/tests/data/test124 index 721f3271f3..f8c2060948 100644 --- a/tests/data/test124 +++ b/tests/data/test124 @@ -33,5 +33,6 @@ PASV TYPE I SIZE 124 RETR 124 +QUIT diff --git a/tests/data/test125 b/tests/data/test125 index 57f8e01057..715eb472e3 100644 --- a/tests/data/test125 +++ b/tests/data/test125 @@ -28,5 +28,6 @@ USER anonymous PASS curl_by_daniel@haxx.se PWD CWD path +QUIT diff --git a/tests/data/test126 b/tests/data/test126 index 1c32165230..e670a25505 100644 --- a/tests/data/test126 +++ b/tests/data/test126 @@ -33,5 +33,6 @@ EPSV TYPE I SIZE 126 RETR 126 +QUIT diff --git a/tests/data/test127 b/tests/data/test127 index aafe559d11..5df4e6aff9 100644 --- a/tests/data/test127 +++ b/tests/data/test127 @@ -31,5 +31,6 @@ PASV TYPE I SIZE 127 RETR 127 +QUIT diff --git a/tests/data/test128 b/tests/data/test128 index a09631e0ca..8e5d99106f 100644 --- a/tests/data/test128 +++ b/tests/data/test128 @@ -33,6 +33,7 @@ PWD EPSV TYPE I STOR 128 +QUIT file diff --git a/tests/data/test130 b/tests/data/test130 index 5441f1c350..90cd4f7531 100644 --- a/tests/data/test130 +++ b/tests/data/test130 @@ -51,5 +51,6 @@ PWD EPSV TYPE A LIST +QUIT diff --git a/tests/data/test131 b/tests/data/test131 index 767fc2c84d..84d3fcce81 100644 --- a/tests/data/test131 +++ b/tests/data/test131 @@ -51,5 +51,6 @@ PWD EPSV TYPE A LIST +QUIT diff --git a/tests/data/test132 b/tests/data/test132 index 1d5cf53852..d3c2711dcf 100644 --- a/tests/data/test132 +++ b/tests/data/test132 @@ -51,5 +51,6 @@ PWD EPSV TYPE A LIST +QUIT diff --git a/tests/data/test133 b/tests/data/test133 index f05dd1f29e..d2dad20c73 100644 --- a/tests/data/test133 +++ b/tests/data/test133 @@ -51,5 +51,6 @@ PWD EPSV TYPE A LIST +QUIT diff --git a/tests/data/test134 b/tests/data/test134 index ae5564bc7a..949ef42571 100644 --- a/tests/data/test134 +++ b/tests/data/test134 @@ -51,5 +51,6 @@ PWD EPSV TYPE A LIST +QUIT diff --git a/tests/data/test135 b/tests/data/test135 index 5d63c2954c..d8f4546cf4 100644 --- a/tests/data/test135 +++ b/tests/data/test135 @@ -38,5 +38,6 @@ TYPE I SIZE 135 REST 4 RETR 135 +QUIT diff --git a/tests/data/test136 b/tests/data/test136 index 3847f8f46f..5e6059bd34 100644 --- a/tests/data/test136 +++ b/tests/data/test136 @@ -28,5 +28,6 @@ EPSV TYPE I SIZE 136 RETR 136 +QUIT diff --git a/tests/data/test137 b/tests/data/test137 index 65a7bc762c..94b2d67238 100644 --- a/tests/data/test137 +++ b/tests/data/test137 @@ -33,5 +33,6 @@ EPSV TYPE I SIZE 137 RETR 137 +QUIT diff --git a/tests/data/test138 b/tests/data/test138 index af862e74ee..76c91120aa 100644 --- a/tests/data/test138 +++ b/tests/data/test138 @@ -36,5 +36,6 @@ EPSV TYPE I SIZE 138 RETR 138 +QUIT diff --git a/tests/data/test139 b/tests/data/test139 index 8d58a9b4ee..95fc7958c0 100644 --- a/tests/data/test139 +++ b/tests/data/test139 @@ -33,5 +33,6 @@ EPSV TYPE I SIZE 139 RETR 139 +QUIT diff --git a/tests/data/test140 b/tests/data/test140 index e0718e111a..5112dfa91a 100644 --- a/tests/data/test140 +++ b/tests/data/test140 @@ -27,6 +27,7 @@ USER anonymous PASS curl_by_daniel@haxx.se PWD CWD blalbla -MDTM 140 +MDTM 140 +QUIT diff --git a/tests/data/test141 b/tests/data/test141 index 2088f93aa5..f47de51de4 100644 --- a/tests/data/test141 +++ b/tests/data/test141 @@ -31,6 +31,7 @@ MDTM 141 TYPE I SIZE 141 REST 0 +QUIT Last-Modified: Wed, 09 Apr 2003 10:26:59 GMT diff --git a/tests/data/test143 b/tests/data/test143 index 567a2d6721..c8a8cbbc3b 100644 --- a/tests/data/test143 +++ b/tests/data/test143 @@ -30,5 +30,6 @@ EPSV TYPE A SIZE 143 RETR 143 +QUIT diff --git a/tests/data/test144 b/tests/data/test144 index 5ca145dc31..7afaf94331 100644 --- a/tests/data/test144 +++ b/tests/data/test144 @@ -35,5 +35,6 @@ PWD PORT 127,0,0,1,243,212 TYPE A NLST +QUIT diff --git a/tests/data/test145 b/tests/data/test145 index 03f3804cf3..3747a98b5a 100644 --- a/tests/data/test145 +++ b/tests/data/test145 @@ -38,5 +38,6 @@ PWD PORT 127,0,0,1,243,212 TYPE A NLST +QUIT diff --git a/tests/data/test146 b/tests/data/test146 index 88690c9540..1909b6b8c9 100644 --- a/tests/data/test146 +++ b/tests/data/test146 @@ -42,5 +42,6 @@ EPSV TYPE I SIZE 146 RETR 146 +QUIT diff --git a/tests/data/test147 b/tests/data/test147 index 9fbcaf26e9..35f7f66767 100644 --- a/tests/data/test147 +++ b/tests/data/test147 @@ -44,5 +44,6 @@ EPSV TYPE I SIZE 147 RETR 147 +QUIT diff --git a/tests/data/test148 b/tests/data/test148 index ba0e783a93..454fee3aec 100644 --- a/tests/data/test148 +++ b/tests/data/test148 @@ -37,5 +37,6 @@ PASS curl_by_daniel@haxx.se PWD CWD attempt MKD attempt +QUIT diff --git a/tests/data/test149 b/tests/data/test149 index 2a8097baae..b42477b79e 100644 --- a/tests/data/test149 +++ b/tests/data/test149 @@ -39,6 +39,7 @@ CWD dir2 EPSV TYPE I STOR 148 +QUIT send away this contents diff --git a/tests/data/test505 b/tests/data/test505 index 7348995455..84cb009109 100644 --- a/tests/data/test505 +++ b/tests/data/test505 @@ -44,4 +44,15 @@ upload works? + +USER anonymous +PASS curl_by_daniel@haxx.se +PWD +EPSV +TYPE I +STOR 505 +RNFR 505 +RNTO 505-forreal +QUIT +