aboutsummaryrefslogtreecommitdiff
path: root/lib/ftp.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2003-08-08 09:55:16 +0000
committerDaniel Stenberg <daniel@haxx.se>2003-08-08 09:55:16 +0000
commit7954eee6396965b424725c40c1dbf8020134a776 (patch)
tree7297c9158718dc4a008478c8070331707c23c6f7 /lib/ftp.c
parentf9f1f0e31635a551f51d2b9e4a7afde4ad4027ca (diff)
re-arranged the cwd/mkd stuff a bit
Diffstat (limited to 'lib/ftp.c')
-rw-r--r--lib/ftp.c88
1 files changed, 50 insertions, 38 deletions
diff --git a/lib/ftp.c b/lib/ftp.c
index 8d40a8c20..52edd1763 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -731,36 +731,6 @@ CURLcode ftp_sendquote(struct connectdata *conn, struct curl_slist *quote)
/***********************************************************************
*
- * ftp_cwd()
- *
- * Send 'CWD' to the remote server to Change Working Directory.
- * It is the ftp version of the unix 'cd' command.
- */
-static
-CURLcode ftp_cwd(struct connectdata *conn, char *path)
-{
- ssize_t nread;
- int ftpcode;
- CURLcode result;
-
- FTPSENDF(conn, "CWD %s", path);
- result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
- if (result)
- return result;
-
- /* According to RFC959, CWD is supposed to return 250 on success, but
- there seem to be non-compliant FTP servers out there that return 200,
- so we accept any '2xy' code here. */
- if (ftpcode/100 != 2) {
- failf(conn->data, "Couldn't cd to %s", path);
- return CURLE_FTP_ACCESS_DENIED;
- }
-
- return CURLE_OK;
-}
-
-/***********************************************************************
- *
* ftp_getfiletime()
*
* Get the timestamp of the given file.
@@ -2340,6 +2310,8 @@ CURLcode Curl_ftp_disconnect(struct connectdata *conn)
* ftp_mkd()
*
* Makes a directory on the FTP server.
+ *
+ * Calls failf()
*/
CURLcode ftp_mkd(struct connectdata *conn, char *path)
{
@@ -2357,11 +2329,15 @@ CURLcode ftp_mkd(struct connectdata *conn, char *path)
switch(ftpcode) {
case 257:
/* success! */
- infof( conn->data , "Created Remote Directory %s\n" , path );
+ infof( conn->data , "Created remote directory %s\n" , path );
+ break;
+ case 550:
+ failf(conn->data, "Permission denied to make directory %s", path);
+ result = CURLE_FTP_ACCESS_DENIED;
break;
default:
- infof(conn->data, "unrecognized MKD response %d\n", result );
- result = ~CURLE_OK;
+ failf(conn->data, "unrecognized MKD response: %d", ftpcode );
+ result = CURLE_FTP_ACCESS_DENIED;
break;
}
return result;
@@ -2369,21 +2345,57 @@ CURLcode ftp_mkd(struct connectdata *conn, char *path)
/***********************************************************************
*
+ * ftp_cwd()
+ *
+ * Send 'CWD' to the remote server to Change Working Directory. It is the ftp
+ * version of the unix 'cd' command. This function is only called from the
+ * cwd_and_mkd() function these days.
+ *
+ * This function does NOT call failf().
+ */
+static
+CURLcode ftp_cwd(struct connectdata *conn, char *path)
+{
+ ssize_t nread;
+ int ftpcode;
+ CURLcode result;
+
+ FTPSENDF(conn, "CWD %s", path);
+ result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
+ if (!result) {
+ /* According to RFC959, CWD is supposed to return 250 on success, but
+ there seem to be non-compliant FTP servers out there that return 200,
+ so we accept any '2xy' code here. */
+ if (ftpcode/100 != 2)
+ result = CURLE_FTP_ACCESS_DENIED;
+ }
+
+ return result;
+}
+
+/***********************************************************************
+ *
* ftp_cwd_and_mkd()
*
* Change to the given directory. If the directory is not present, and we
* have been told to allow it, then create the directory and cd to it.
+ *
*/
static CURLcode cwd_and_mkd(struct connectdata *conn, char *path)
{
CURLcode result;
result = ftp_cwd(conn, path);
- if ((CURLE_OK != result) && conn->data->set.ftp_create_missing_dirs) {
- result = ftp_mkd(conn, path);
- if ( CURLE_OK != result)
- return result;
- result = ftp_cwd(conn, path);
+ if (result) {
+ if(conn->data->set.ftp_create_missing_dirs) {
+ result = ftp_mkd(conn, path);
+ if (result)
+ /* ftp_mkd() calls failf() itself */
+ return result;
+ result = ftp_cwd(conn, path);
+ }
+ if(result)
+ failf(conn->data, "Couldn't cd to %s", path);
}
return result;
}