From 546f4dca52cf9689a19dc916a13492e77f8ab436 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Wed, 15 Aug 2001 07:14:51 +0000 Subject: [PATCH] ftp_cwd() abstraction "%" -> "%s" --- lib/ftp.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/ftp.c b/lib/ftp.c index 5938a8955..4c1ba71bc 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -91,8 +91,9 @@ #include "memdebug.h" #endif -/* Used in more than one place in the file */ +/* Local API functions */ static CURLcode _ftp_sendquote(struct connectdata *conn, struct curl_slist *quote); +static CURLcode _ftp_cwd(struct connectdata *conn, char *path); /* easy-to-use macro: */ #define ftpsendf Curl_ftpsendf @@ -586,7 +587,8 @@ CURLcode Curl_ftp_done(struct connectdata *conn) } -static CURLcode _ftp_sendquote(struct connectdata *conn, struct curl_slist *quote) +static +CURLcode _ftp_sendquote(struct connectdata *conn, struct curl_slist *quote) { struct curl_slist *item; ssize_t nread; @@ -595,7 +597,7 @@ static CURLcode _ftp_sendquote(struct connectdata *conn, struct curl_slist *quot item = quote; while (item) { if (item->data) { - ftpsendf(conn->firstsocket, conn, "%", item->data); + ftpsendf(conn->firstsocket, conn, "%s", item->data); nread = Curl_GetFTPResponse(conn->firstsocket, conn->data->buffer, conn, &ftpcode); @@ -614,6 +616,24 @@ static CURLcode _ftp_sendquote(struct connectdata *conn, struct curl_slist *quot return CURLE_OK; } +static +CURLcode _ftp_cwd(struct connectdata *conn, char *path) +{ + ssize_t nread; + int ftpcode; + + ftpsendf(conn->firstsocket, conn, "CWD %s", path); + nread = Curl_GetFTPResponse(conn->firstsocket, + conn->data->buffer, conn, &ftpcode); + if (nread < 0) + return CURLE_OPERATION_TIMEOUTED; + + if (ftpcode != 250) { + failf(conn->data, "Couldn't change back to directory %s", path); + return CURLE_FTP_ACCESS_DENIED; + } +} + static CURLcode _ftp(struct connectdata *conn) { @@ -647,23 +667,15 @@ CURLcode _ftp(struct connectdata *conn) return result; } - if(conn->bits.reuse) { /* This is a re-used connection. Since we change directory to where the transfer is taking place, we must now get back to the original dir where we ended up after login: */ - ftpsendf(conn->firstsocket, conn, "CWD %s", ftp->entrypath); - nread = Curl_GetFTPResponse(conn->firstsocket, buf, conn, &ftpcode); - if(nread < 0) - return CURLE_OPERATION_TIMEOUTED; - - if(ftpcode != 250) { - failf(data, "Couldn't change back to directory %s", ftp->entrypath); - return CURLE_FTP_ACCESS_DENIED; - } + if (conn->bits.reuse) { + if ((result = _ftp_cwd(conn, ftp->entrypath)) != CURLE_OK) + return result; } - /* change directory first! */ if(ftp->dir && ftp->dir[0]) { ftpsendf(conn->firstsocket, conn, "CWD %s", ftp->dir);