ftp_cwd() abstraction

"%" -> "%s"
This commit is contained in:
Sterling Hughes 2001-08-15 07:14:51 +00:00
parent 09a9b57bae
commit 546f4dca52
1 changed files with 26 additions and 14 deletions

View File

@ -91,8 +91,9 @@
#include "memdebug.h" #include "memdebug.h"
#endif #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_sendquote(struct connectdata *conn, struct curl_slist *quote);
static CURLcode _ftp_cwd(struct connectdata *conn, char *path);
/* easy-to-use macro: */ /* easy-to-use macro: */
#define ftpsendf Curl_ftpsendf #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; struct curl_slist *item;
ssize_t nread; ssize_t nread;
@ -595,7 +597,7 @@ static CURLcode _ftp_sendquote(struct connectdata *conn, struct curl_slist *quot
item = quote; item = quote;
while (item) { while (item) {
if (item->data) { if (item->data) {
ftpsendf(conn->firstsocket, conn, "%", item->data); ftpsendf(conn->firstsocket, conn, "%s", item->data);
nread = Curl_GetFTPResponse(conn->firstsocket, nread = Curl_GetFTPResponse(conn->firstsocket,
conn->data->buffer, conn, &ftpcode); conn->data->buffer, conn, &ftpcode);
@ -614,6 +616,24 @@ static CURLcode _ftp_sendquote(struct connectdata *conn, struct curl_slist *quot
return CURLE_OK; 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 static
CURLcode _ftp(struct connectdata *conn) CURLcode _ftp(struct connectdata *conn)
{ {
@ -647,23 +667,15 @@ CURLcode _ftp(struct connectdata *conn)
return result; return result;
} }
if(conn->bits.reuse) {
/* This is a re-used connection. Since we change directory to where the /* 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 transfer is taking place, we must now get back to the original dir
where we ended up after login: */ where we ended up after login: */
ftpsendf(conn->firstsocket, conn, "CWD %s", ftp->entrypath); if (conn->bits.reuse) {
nread = Curl_GetFTPResponse(conn->firstsocket, buf, conn, &ftpcode); if ((result = _ftp_cwd(conn, ftp->entrypath)) != CURLE_OK)
if(nread < 0) return result;
return CURLE_OPERATION_TIMEOUTED;
if(ftpcode != 250) {
failf(data, "Couldn't change back to directory %s", ftp->entrypath);
return CURLE_FTP_ACCESS_DENIED;
}
} }
/* change directory first! */ /* change directory first! */
if(ftp->dir && ftp->dir[0]) { if(ftp->dir && ftp->dir[0]) {
ftpsendf(conn->firstsocket, conn, "CWD %s", ftp->dir); ftpsendf(conn->firstsocket, conn, "CWD %s", ftp->dir);