From 77268e064905931536498a87213ebece96a64f9b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 27 Feb 2004 07:08:37 +0000 Subject: Joe Halpin made the FTP code send 'QUIT' on the control connection before it disconnects the TCP connection, like a good ftp client should! --- lib/ftp.c | 23 ++++++++++++++--------- lib/urldata.h | 4 ++++ 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/ftp.c b/lib/ftp.c index d6c161f16..0622e7edb 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 33a3fe120..821a0c37e 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() */ }; /**************************************************************************** -- cgit v1.2.3