]> granicus.if.org Git - curl/commitdiff
Joe Halpin made the FTP code send 'QUIT' on the control connection before
authorDaniel Stenberg <daniel@haxx.se>
Fri, 27 Feb 2004 07:08:37 +0000 (07:08 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 27 Feb 2004 07:08:37 +0000 (07:08 +0000)
it disconnects the TCP connection, like a good ftp client should!

49 files changed:
lib/ftp.c
lib/urldata.h
tests/data/test100
tests/data/test101
tests/data/test102
tests/data/test103
tests/data/test104
tests/data/test105
tests/data/test106
tests/data/test107
tests/data/test108
tests/data/test109
tests/data/test110
tests/data/test111
tests/data/test112
tests/data/test115
tests/data/test116
tests/data/test117
tests/data/test118
tests/data/test119
tests/data/test120
tests/data/test121
tests/data/test122
tests/data/test123
tests/data/test124
tests/data/test125
tests/data/test126
tests/data/test127
tests/data/test128
tests/data/test130
tests/data/test131
tests/data/test132
tests/data/test133
tests/data/test134
tests/data/test135
tests/data/test136
tests/data/test137
tests/data/test138
tests/data/test139
tests/data/test140
tests/data/test141
tests/data/test143
tests/data/test144
tests/data/test145
tests/data/test146
tests/data/test147
tests/data/test148
tests/data/test149
tests/data/test505

index d6c161f1698e9691657405571d6f76d699e9b998..0622e7edb27c6821fc3beb2c85b06095adfc4f5b 100644 (file)
--- 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) {
index 33a3fe120b01d5ed5b418d4c73786cf0a1c28a9f..821a0c37ea43a26bbe44283de8e645080b0b6eb5 100644 (file)
@@ -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() */
 };
 
 /****************************************************************************
index 8fbb1714e9c414598195c2369e23fd2ce8e2a159..aad4601614d531c27e427cf0dfd514a2bff7cc54 100644 (file)
@@ -43,5 +43,6 @@ PWD
 EPSV\r
 TYPE A\r
 LIST\r
+QUIT\r
 </protocol>
 </verify>
index eabc6e2efcd96cf743cc3f7fb2ff48f967d29a89..67f5968e45b751e616053e578bfa00d528ad0c1f 100644 (file)
@@ -43,5 +43,6 @@ PWD
 PORT 127,0,0,1,243,212\r
 TYPE A\r
 LIST\r
+QUIT\r
 </protocol>
 </verify>
index a124581fd85faa864d68b5c7ebdf46a36aff5225..ebb58e898c05ea676d99e20a93d7e6ca3f508843 100644 (file)
@@ -38,5 +38,6 @@ PASV
 TYPE I\r
 SIZE 102\r
 RETR 102\r
+QUIT\r
 </protocol>
 </verify>
index e46391318615a7fa2c98c002b594a2b279d2a9bf..d8aa339c34a98823c61be8ac62a41dfa3673b389 100644 (file)
@@ -40,5 +40,6 @@ PORT 127,0,0,1,246,33
 TYPE I\r
 SIZE 103\r
 RETR 103\r
+QUIT\r
 </protocol>
 </verify>
index 4a72caec726f74d5921edd29f9c3f2e4a4cc459b..b0b9c45efc06f654bd4f6b7d249b50d19f1f1a4e 100644 (file)
@@ -30,5 +30,6 @@ MDTM 103
 TYPE I\r
 SIZE 103\r
 REST 0\r
+QUIT\r
 </protocol>
 </verify>
index b077ecc750990863ee5265831061d2579c15e743..0245592e3fff344c6c7aa8c9bc811a87349b2b8a 100644 (file)
@@ -38,5 +38,6 @@ PASV
 TYPE A\r
 SIZE 103\r
 RETR 103\r
+QUIT\r
 </protocol>
 </verify>
index c6a66cd1b4ba82c96094510c81d8d08dbc935215..359af4f2ea88071825ccf154cd519cb66a816b18 100644 (file)
@@ -35,5 +35,6 @@ EPSV
 TYPE A\r
 SIZE 106\r
 RETR 106\r
+QUIT\r
 </protocol>
 </verify>
index bb69f16b79fb003e0b044f17d54047fd931e52bd..c97dbb9a4661be1494a4456d598eeb02f59a57cd 100644 (file)
@@ -37,5 +37,6 @@ PWD
 EPSV\r
 TYPE I\r
 STOR 107\r
+QUIT\r
 </protocol>
 </verify>
index 27c5c6d237a66e52e0a3d5bb60080fb9d854b49b..7ab7b4791d5ce837cdd0a495fd09d2d44b7f7784 100644 (file)
@@ -38,6 +38,7 @@ CWD RETR
 PORT 127,0,0,1,5,109\r
 TYPE I\r
 STOR 108\r
+QUIT\r
 </protocol>
 <upload>
 Moooooooooooo
index 4aad721236089d4d52af9c9fb97d07490c8911a0..1362d5b317a70e3ed3fd0e1f978112e067cda7b7 100644 (file)
@@ -32,6 +32,7 @@ PWD
 EPSV\r
 TYPE I\r
 APPE 109\r
+QUIT\r
 </protocol>
 <upload>
 Moooooooooooo
index 4014daa82caaaf777bf51ab0f6dff3820a72bee6..38f40c7b7c25c1ad6b90d390aa17502ced7194ee 100644 (file)
@@ -39,5 +39,6 @@ TYPE I
 SIZE 110\r
 REST 20\r
 RETR 110\r
+QUIT\r
 </protocol>
 </verify>
index 78b6141af08d83f50944b5867da2f0d8f93ad37e..0664bfd7706b062f453677b096feb18beda21815 100644 (file)
@@ -32,5 +32,6 @@ PWD
 EPSV\r
 TYPE I\r
 SIZE 111\r
+QUIT\r
 </protocol>
 </verify>
index e519d675658f4c09f12628e9694a2be8f86ae10e..fe3dd52cbb2ee3c9e84cec6f29ad165d9c393b5b 100644 (file)
@@ -31,6 +31,7 @@ PWD
 EPSV\r
 TYPE I\r
 APPE 112\r
+QUIT\r
 </protocol>
 <upload>
  gonna upload
index 204b0ccd987903a41c70c111eadc750f743e0f76..03a5caf1def2d248ac88b1215f0914bdcee25d8e 100644 (file)
@@ -30,5 +30,6 @@ PASS curl_by_daniel@haxx.se
 PWD\r
 EPSV\r
 PASV\r
+QUIT\r
 </protocol>
 </verify>
index 0bc8620c8a6442094e33013cf67057ca5bccc5e9..57ad11ae2bc791b7ee82d0e15ccf80754f199ef6 100644 (file)
@@ -32,5 +32,6 @@ REPLY PORT 314 bluah you f00l!
 USER anonymous\r
 PASS curl_by_daniel@haxx.se\r
 PWD\r
+QUIT\r
 </protocol>
 </verify>
index 428cbee9da8ac4bcc56895c4f658e0bfc29270e1..43a10958e6f3c0e683f8bcaf115766a586679fc8 100644 (file)
@@ -31,5 +31,6 @@ PWD
 EPSV\r
 PASV\r
 TYPE I\r
+QUIT\r
 </protocol>
 </verify>
index b97c0c961550490582361fc8ba24486fe65aa1e4..0cce25cb84214d9cc1ceb35ff69fd89fa9c0f856 100644 (file)
@@ -33,5 +33,6 @@ PASV
 TYPE I\r
 SIZE 118\r
 RETR 118\r
+QUIT\r
 </protocol>
 </verify>
index 2e53a82b2cc060f5b51661cb21e9fe2a00e206f1..96d30d7e7d555ab8f66e509135b8096fcee7cf5f 100644 (file)
@@ -35,5 +35,6 @@ PWD
 TYPE I\r
 SIZE 119\r
 RETR 119\r
+QUIT\r
 </protocol>
 </verify>
index 2fcf0153901894ebd232176a127884ee1d6a5500..ebc5691cd86603df7b6db1a6bfa1666863030f4e 100644 (file)
@@ -38,5 +38,6 @@ TYPE I
 SIZE 120\r
 RETR 120\r
 DELE file\r
+QUIT\r
 </protocol>
 </verify>
index 64d26f9e29f405b00de94ada6af86f2acb474c3d..427d88ba7ad913c75d35e6ee03c5d858e12fce75 100644 (file)
@@ -35,5 +35,6 @@ TYPE I
 SIZE 121\r
 RETR 121\r
 DELE after_transfer\r
+QUIT\r
 </protocol>
 </verify>
index 3e385502aab4221378fb4b0441a8a4b6d3d77c03..5b7bafe758d321efcf81d8992d03f9c857a78dfd 100644 (file)
@@ -31,5 +31,6 @@ EPSV
 PASV\r
 TYPE I\r
 SIZE 122\r
+QUIT\r
 </protocol>
 </verify>
index 066d70960510e179eda453f9c6eaf3555e627835..3825360b07f107bb5242f306b1f22b3850ba344f 100644 (file)
@@ -26,5 +26,6 @@ PASS curl_by_daniel@haxx.se
 PWD\r
 EPSV\r
 TYPE I\r
+QUIT\r
 </protocol>
 </verify>
index 721f3271f33430c1b36e8ce6e74a39097fd82df2..f8c20609481ca36e76120064504c263fd6ce34c9 100644 (file)
@@ -33,5 +33,6 @@ PASV
 TYPE I\r
 SIZE 124\r
 RETR 124\r
+QUIT\r
 </protocol>
 </verify>
index 57f8e01057e8f6f64e69d16bebec1e20555ebe68..715eb472e310e00a25262dca46af6c2e99fee972 100644 (file)
@@ -28,5 +28,6 @@ USER anonymous
 PASS curl_by_daniel@haxx.se\r
 PWD\r
 CWD path\r
+QUIT\r
 </protocol>
 </verify>
index 1c3216523067af3e5b3decc66f54e5900916da58..e670a2550599c52f29d221b835b34ae1f38289e4 100644 (file)
@@ -33,5 +33,6 @@ EPSV
 TYPE I\r
 SIZE 126\r
 RETR 126\r
+QUIT\r
 </protocol>
 </verify>
index aafe559d11036d2be8ba5b26297ea651fee932ec..5df4e6aff99a5008d8cf37dab6fde1d78ff0bef4 100644 (file)
@@ -31,5 +31,6 @@ PASV
 TYPE I\r
 SIZE 127\r
 RETR 127\r
+QUIT\r
 </protocol>
 </verify>
index a09631e0ca74cdbd17afc10dbb437293dfd06fc0..8e5d99106f558e386e0bbc88327b85ac08f2b31d 100644 (file)
@@ -33,6 +33,7 @@ PWD
 EPSV\r
 TYPE I\r
 STOR 128\r
+QUIT\r
 </protocol>
 <upload>
 file\r
index 5441f1c350dd5232687e68855ef8919e327dc2a6..90cd4f753145515ced652c04d44c095ea1afea89 100644 (file)
@@ -51,5 +51,6 @@ PWD
 EPSV\r
 TYPE A\r
 LIST\r
+QUIT\r
 </protocol>
 </verify>
index 767fc2c84dd4ddd0fbf31ae40f221e58c13fe108..84d3fcce81bec6630986a8858e8a2cc83aeb7dbd 100644 (file)
@@ -51,5 +51,6 @@ PWD
 EPSV\r
 TYPE A\r
 LIST\r
+QUIT\r
 </protocol>
 </verify>
index 1d5cf53852c0bac30ee21a97db98f7ee06100c15..d3c2711dcfca2fd73fd57c56c526a04256606812 100644 (file)
@@ -51,5 +51,6 @@ PWD
 EPSV\r
 TYPE A\r
 LIST\r
+QUIT\r
 </protocol>
 </verify>
index f05dd1f29e56e3c2992daceaf26807ec47f70a16..d2dad20c733a0721b73ba2bbf2ab2fdba028be5a 100644 (file)
@@ -51,5 +51,6 @@ PWD
 EPSV\r
 TYPE A\r
 LIST\r
+QUIT\r
 </protocol>
 </verify>
index ae5564bc7adb86dc36c614b7be6be342851e97a4..949ef42571bc34c531320cc26d17020b085aaf67 100644 (file)
@@ -51,5 +51,6 @@ PWD
 EPSV\r
 TYPE A\r
 LIST\r
+QUIT\r
 </protocol>
 </verify>
index 5d63c2954c1e4226947a917ddb1ec4c9c9fbca0f..d8f4546cf464c93618cec2909218397c9daf197a 100644 (file)
@@ -38,5 +38,6 @@ TYPE I
 SIZE 135\r
 REST 4\r
 RETR 135\r
+QUIT\r
 </protocol>
 </verify>
index 3847f8f46f7686b705b6b9f9ffc6f9bc6f7723af..5e6059bd34943898dc29e3bfa1ea72654d3bc1c6 100644 (file)
@@ -28,5 +28,6 @@ EPSV
 TYPE I\r
 SIZE 136\r
 RETR 136\r
+QUIT\r
 </protocol>
 </verify>
index 65a7bc762c27ae2b226bd826fe4e478e39951d3d..94b2d67238b9097a3013ef2872606e612a83ac8a 100644 (file)
@@ -33,5 +33,6 @@ EPSV
 TYPE I\r
 SIZE 137\r
 RETR 137\r
+QUIT\r
 </protocol>
 </verify>
index af862e74ee5a730de464880f21a89f68755fa740..76c91120aa57ce24f2e60bc6cdf2a4c91c7462d2 100644 (file)
@@ -36,5 +36,6 @@ EPSV
 TYPE I\r
 SIZE 138\r
 RETR 138\r
+QUIT\r
 </protocol>
 </verify>
index 8d58a9b4ee2cc922475fd9073af75c7c6173dcf6..95fc7958c04873996b2962acc56f6ddae94d4502 100644 (file)
@@ -33,5 +33,6 @@ EPSV
 TYPE I\r
 SIZE 139\r
 RETR 139\r
+QUIT\r
 </protocol>
 </verify>
index e0718e111aefa108d54d0eb27a235f31cf634393..5112dfa91a825732e0003799d98eee3fcb9ac498 100644 (file)
@@ -27,6 +27,7 @@ USER anonymous
 PASS curl_by_daniel@haxx.se\r
 PWD\r
 CWD blalbla\r
-MDTM 140
+MDTM 140\r
+QUIT\r
 </protocol>
 </verify>
index 2088f93aa5174be463a8666b7170b5a268652cdd..f47de51de4e6de50d8a3103108023293f04fd89f 100644 (file)
@@ -31,6 +31,7 @@ MDTM 141
 TYPE I\r
 SIZE 141\r
 REST 0\r
+QUIT\r
 </protocol>
 <stdout>
 Last-Modified: Wed, 09 Apr 2003 10:26:59 GMT
index 567a2d67210a18dadd216cab3391e7ae517c2c7e..c8a8cbbc3b5fc8535b5193fb0255211c1ec9b044 100644 (file)
@@ -30,5 +30,6 @@ EPSV
 TYPE A\r
 SIZE 143\r
 RETR 143\r
+QUIT\r
 </protocol>
 </verify>
index 5ca145dc316fc8e3ae8862e70d23fb1796d4e2fd..7afaf94331755b7bf6fcb11b8ffc08c5de372af5 100644 (file)
@@ -35,5 +35,6 @@ PWD
 PORT 127,0,0,1,243,212\r
 TYPE A\r
 NLST\r
+QUIT\r
 </protocol>
 </verify>
index 03f3804cf36bf8c28ce3f61ccb612f6db5896ee9..3747a98b5af40f7a89ba25e0bcdf3e528e0b3db6 100644 (file)
@@ -38,5 +38,6 @@ PWD
 PORT 127,0,0,1,243,212\r
 TYPE A\r
 NLST\r
+QUIT\r
 </protocol>
 </verify>
index 88690c95400a9101d7de17ad027499c5bd821ce7..1909b6b8c992790b57cec0d53d6748f7caba5bfa 100644 (file)
@@ -42,5 +42,6 @@ EPSV
 TYPE I\r
 SIZE 146\r
 RETR 146\r
+QUIT\r
 </protocol>
 </verify>
index 9fbcaf26e95d871f26655d861c2601b238987c56..35f7f66767293abf48b1f38586156ba2688138a5 100644 (file)
@@ -44,5 +44,6 @@ EPSV
 TYPE I\r
 SIZE 147\r
 RETR 147\r
+QUIT\r
 </protocol>
 </verify>
index ba0e783a93fee28ee9cbb74bedbce47b66f60511..454fee3aece739442b8c41973a2f94775d693a18 100644 (file)
@@ -37,5 +37,6 @@ PASS curl_by_daniel@haxx.se
 PWD\r
 CWD attempt\r
 MKD attempt\r
+QUIT\r
 </protocol>
 </verify>
index 2a8097baae936b333b7fd93c7a79c13339172b41..b42477b79edf29c10b0e862a4155c41543254ce8 100644 (file)
@@ -39,6 +39,7 @@ CWD dir2
 EPSV\r
 TYPE I\r
 STOR 148\r
+QUIT\r
 </protocol>
 <file name="log/upload148">
 send away this contents
index 73489954556a57a2aec90058a7f7ec7ac14c3b95..84cb0091099cb6a6d23475c2e95b1668d884001a 100644 (file)
@@ -44,4 +44,15 @@ upload
 
 works?
 </upload>
+<protocol>
+USER anonymous\r
+PASS curl_by_daniel@haxx.se\r
+PWD\r
+EPSV\r
+TYPE I\r
+STOR 505\r
+RNFR 505\r
+RNTO 505-forreal\r
+QUIT\r
+</protocol>
 </verify>