Joe Halpin made the FTP code send 'QUIT' on the control connection before

it disconnects the TCP connection, like a good ftp client should!
This commit is contained in:
Daniel Stenberg 2004-02-27 07:08:37 +00:00
parent 1ceb77b4dc
commit 77268e0649
49 changed files with 76 additions and 10 deletions

View File

@ -2288,12 +2288,14 @@ CURLcode ftp_perform(struct connectdata *conn,
* parts etc as a wrapper to the actual DO function (ftp_perform). * parts etc as a wrapper to the actual DO function (ftp_perform).
* *
* The input argument is already checked for validity. * 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 Curl_ftp(struct connectdata *conn)
{ {
CURLcode retcode=CURLE_OK; CURLcode retcode=CURLE_OK;
bool connected=0; bool connected=0;
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
struct FTP *ftp; struct FTP *ftp;
@ -2304,6 +2306,7 @@ CURLcode Curl_ftp(struct connectdata *conn)
/* the ftp struct is already inited in ftp_connect() */ /* the ftp struct is already inited in ftp_connect() */
ftp = conn->proto.ftp; ftp = conn->proto.ftp;
ftp->ctl_valid = FALSE;
conn->size = -1; /* make sure this is unknown at this point */ conn->size = -1; /* make sure this is unknown at this point */
Curl_pgrsSetUploadCounter(data, 0); Curl_pgrsSetUploadCounter(data, 0);
@ -2386,6 +2389,7 @@ CURLcode Curl_ftp(struct connectdata *conn)
else else
freedirs(ftp); freedirs(ftp);
ftp->ctl_valid = TRUE;
return retcode; return retcode;
} }
@ -2452,11 +2456,13 @@ CURLcode Curl_ftp_quit(struct connectdata *conn)
{ {
ssize_t nread; ssize_t nread;
int ftpcode; int ftpcode;
CURLcode ret; CURLcode ret = CURLE_OK;
ret = Curl_ftpsendf(conn, "%s", "QUIT"); if(conn->proto.ftp->ctl_valid) {
if(CURLE_OK == ret) ret = Curl_ftpsendf(conn, "%s", "QUIT");
ret = Curl_GetFTPResponse(&nread, conn, &ftpcode); if(CURLE_OK == ret)
ret = Curl_GetFTPResponse(&nread, conn, &ftpcode);
}
return ret; return ret;
} }
@ -2472,15 +2478,14 @@ CURLcode Curl_ftp_disconnect(struct connectdata *conn)
{ {
struct FTP *ftp= conn->proto.ftp; struct FTP *ftp= conn->proto.ftp;
#if 0
/* We cannot send quit unconditionally. If this connection is stale or /* We cannot send quit unconditionally. If this connection is stale or
bad in any way, sending quit and waiting around here will make the 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. 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 */ (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! */ /* The FTP session may or may not have been allocated/setup at this point! */
if(ftp) { if(ftp) {

View File

@ -258,6 +258,10 @@ struct FTP {
long response_time; /* When no timeout is given, this is the amount of long response_time; /* When no timeout is given, this is the amount of
seconds we await for an FTP response. Initialized seconds we await for an FTP response. Initialized
in Curl_ftp_connect() */ 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() */
}; };
/**************************************************************************** /****************************************************************************

View File

@ -43,5 +43,6 @@ PWD
EPSV EPSV
TYPE A TYPE A
LIST LIST
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -43,5 +43,6 @@ PWD
PORT 127,0,0,1,243,212 PORT 127,0,0,1,243,212
TYPE A TYPE A
LIST LIST
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -38,5 +38,6 @@ PASV
TYPE I TYPE I
SIZE 102 SIZE 102
RETR 102 RETR 102
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -40,5 +40,6 @@ PORT 127,0,0,1,246,33
TYPE I TYPE I
SIZE 103 SIZE 103
RETR 103 RETR 103
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -30,5 +30,6 @@ MDTM 103
TYPE I TYPE I
SIZE 103 SIZE 103
REST 0 REST 0
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -38,5 +38,6 @@ PASV
TYPE A TYPE A
SIZE 103 SIZE 103
RETR 103 RETR 103
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -35,5 +35,6 @@ EPSV
TYPE A TYPE A
SIZE 106 SIZE 106
RETR 106 RETR 106
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -37,5 +37,6 @@ PWD
EPSV EPSV
TYPE I TYPE I
STOR 107 STOR 107
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -38,6 +38,7 @@ CWD RETR
PORT 127,0,0,1,5,109 PORT 127,0,0,1,5,109
TYPE I TYPE I
STOR 108 STOR 108
QUIT
</protocol> </protocol>
<upload> <upload>
Moooooooooooo Moooooooooooo

View File

@ -32,6 +32,7 @@ PWD
EPSV EPSV
TYPE I TYPE I
APPE 109 APPE 109
QUIT
</protocol> </protocol>
<upload> <upload>
Moooooooooooo Moooooooooooo

View File

@ -39,5 +39,6 @@ TYPE I
SIZE 110 SIZE 110
REST 20 REST 20
RETR 110 RETR 110
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -32,5 +32,6 @@ PWD
EPSV EPSV
TYPE I TYPE I
SIZE 111 SIZE 111
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -31,6 +31,7 @@ PWD
EPSV EPSV
TYPE I TYPE I
APPE 112 APPE 112
QUIT
</protocol> </protocol>
<upload> <upload>
gonna upload gonna upload

View File

@ -30,5 +30,6 @@ PASS curl_by_daniel@haxx.se
PWD PWD
EPSV EPSV
PASV PASV
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -32,5 +32,6 @@ REPLY PORT 314 bluah you f00l!
USER anonymous USER anonymous
PASS curl_by_daniel@haxx.se PASS curl_by_daniel@haxx.se
PWD PWD
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -31,5 +31,6 @@ PWD
EPSV EPSV
PASV PASV
TYPE I TYPE I
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -33,5 +33,6 @@ PASV
TYPE I TYPE I
SIZE 118 SIZE 118
RETR 118 RETR 118
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -35,5 +35,6 @@ PWD
TYPE I TYPE I
SIZE 119 SIZE 119
RETR 119 RETR 119
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -38,5 +38,6 @@ TYPE I
SIZE 120 SIZE 120
RETR 120 RETR 120
DELE file DELE file
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -35,5 +35,6 @@ TYPE I
SIZE 121 SIZE 121
RETR 121 RETR 121
DELE after_transfer DELE after_transfer
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -31,5 +31,6 @@ EPSV
PASV PASV
TYPE I TYPE I
SIZE 122 SIZE 122
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -26,5 +26,6 @@ PASS curl_by_daniel@haxx.se
PWD PWD
EPSV EPSV
TYPE I TYPE I
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -33,5 +33,6 @@ PASV
TYPE I TYPE I
SIZE 124 SIZE 124
RETR 124 RETR 124
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -28,5 +28,6 @@ USER anonymous
PASS curl_by_daniel@haxx.se PASS curl_by_daniel@haxx.se
PWD PWD
CWD path CWD path
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -33,5 +33,6 @@ EPSV
TYPE I TYPE I
SIZE 126 SIZE 126
RETR 126 RETR 126
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -31,5 +31,6 @@ PASV
TYPE I TYPE I
SIZE 127 SIZE 127
RETR 127 RETR 127
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -33,6 +33,7 @@ PWD
EPSV EPSV
TYPE I TYPE I
STOR 128 STOR 128
QUIT
</protocol> </protocol>
<upload> <upload>
file file

View File

@ -51,5 +51,6 @@ PWD
EPSV EPSV
TYPE A TYPE A
LIST LIST
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -51,5 +51,6 @@ PWD
EPSV EPSV
TYPE A TYPE A
LIST LIST
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -51,5 +51,6 @@ PWD
EPSV EPSV
TYPE A TYPE A
LIST LIST
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -51,5 +51,6 @@ PWD
EPSV EPSV
TYPE A TYPE A
LIST LIST
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -51,5 +51,6 @@ PWD
EPSV EPSV
TYPE A TYPE A
LIST LIST
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -38,5 +38,6 @@ TYPE I
SIZE 135 SIZE 135
REST 4 REST 4
RETR 135 RETR 135
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -28,5 +28,6 @@ EPSV
TYPE I TYPE I
SIZE 136 SIZE 136
RETR 136 RETR 136
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -33,5 +33,6 @@ EPSV
TYPE I TYPE I
SIZE 137 SIZE 137
RETR 137 RETR 137
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -36,5 +36,6 @@ EPSV
TYPE I TYPE I
SIZE 138 SIZE 138
RETR 138 RETR 138
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -33,5 +33,6 @@ EPSV
TYPE I TYPE I
SIZE 139 SIZE 139
RETR 139 RETR 139
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -27,6 +27,7 @@ USER anonymous
PASS curl_by_daniel@haxx.se PASS curl_by_daniel@haxx.se
PWD PWD
CWD blalbla CWD blalbla
MDTM 140 MDTM 140
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -31,6 +31,7 @@ MDTM 141
TYPE I TYPE I
SIZE 141 SIZE 141
REST 0 REST 0
QUIT
</protocol> </protocol>
<stdout> <stdout>
Last-Modified: Wed, 09 Apr 2003 10:26:59 GMT Last-Modified: Wed, 09 Apr 2003 10:26:59 GMT

View File

@ -30,5 +30,6 @@ EPSV
TYPE A TYPE A
SIZE 143 SIZE 143
RETR 143 RETR 143
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -35,5 +35,6 @@ PWD
PORT 127,0,0,1,243,212 PORT 127,0,0,1,243,212
TYPE A TYPE A
NLST NLST
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -38,5 +38,6 @@ PWD
PORT 127,0,0,1,243,212 PORT 127,0,0,1,243,212
TYPE A TYPE A
NLST NLST
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -42,5 +42,6 @@ EPSV
TYPE I TYPE I
SIZE 146 SIZE 146
RETR 146 RETR 146
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -44,5 +44,6 @@ EPSV
TYPE I TYPE I
SIZE 147 SIZE 147
RETR 147 RETR 147
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -37,5 +37,6 @@ PASS curl_by_daniel@haxx.se
PWD PWD
CWD attempt CWD attempt
MKD attempt MKD attempt
QUIT
</protocol> </protocol>
</verify> </verify>

View File

@ -39,6 +39,7 @@ CWD dir2
EPSV EPSV
TYPE I TYPE I
STOR 148 STOR 148
QUIT
</protocol> </protocol>
<file name="log/upload148"> <file name="log/upload148">
send away this contents send away this contents

View File

@ -44,4 +44,15 @@ upload
works? works?
</upload> </upload>
<protocol>
USER anonymous
PASS curl_by_daniel@haxx.se
PWD
EPSV
TYPE I
STOR 505
RNFR 505
RNTO 505-forreal
QUIT
</protocol>
</verify> </verify>