mirror of
https://github.com/moparisthebest/curl
synced 2024-11-04 08:35:05 -05:00
make the ftp-method multicwd case possible to LIST the root directory of a
server!
This commit is contained in:
parent
cc26cc5dcd
commit
fe85ae15f3
84
lib/ftp.c
84
lib/ftp.c
@ -3719,51 +3719,57 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
|
|||||||
if(!ftpc->dirs)
|
if(!ftpc->dirs)
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
/* parse the URL path into separate path components */
|
/* we have a special case for listing the root dir only */
|
||||||
while ((slash_pos = strchr(cur_pos, '/')) != NULL) {
|
if(strequal(path_to_use, "/")) {
|
||||||
/* 1 or 0 to indicate absolute directory */
|
cur_pos++; /* make it point to the zero byte */
|
||||||
bool absolute_dir = (bool)((cur_pos - data->reqdata.path > 0) &&
|
ftpc->dirs[0] = strdup("/");
|
||||||
(ftpc->dirdepth == 0));
|
ftpc->dirdepth++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* parse the URL path into separate path components */
|
||||||
|
while ((slash_pos = strchr(cur_pos, '/')) != NULL) {
|
||||||
|
/* 1 or 0 to indicate absolute directory */
|
||||||
|
bool absolute_dir = (bool)((cur_pos - data->reqdata.path > 0) &&
|
||||||
|
(ftpc->dirdepth == 0));
|
||||||
|
|
||||||
/* seek out the next path component */
|
/* seek out the next path component */
|
||||||
if (slash_pos-cur_pos) {
|
if (slash_pos-cur_pos) {
|
||||||
/* we skip empty path components, like "x//y" since the FTP command
|
/* we skip empty path components, like "x//y" since the FTP command
|
||||||
CWD requires a parameter and a non-existant parameter a) doesn't
|
CWD requires a parameter and a non-existant parameter a) doesn't
|
||||||
work on many servers and b) has no effect on the others. */
|
work on many servers and b) has no effect on the others. */
|
||||||
int len = (int)(slash_pos - cur_pos + absolute_dir);
|
int len = (int)(slash_pos - cur_pos + absolute_dir);
|
||||||
ftpc->dirs[ftpc->dirdepth] = curl_easy_unescape(conn->data,
|
ftpc->dirs[ftpc->dirdepth] =
|
||||||
cur_pos - absolute_dir,
|
curl_easy_unescape(conn->data, cur_pos - absolute_dir, len, NULL);
|
||||||
len, NULL);
|
if (!ftpc->dirs[ftpc->dirdepth]) { /* run out of memory ... */
|
||||||
if (!ftpc->dirs[ftpc->dirdepth]) { /* run out of memory ... */
|
failf(data, "no memory");
|
||||||
failf(data, "no memory");
|
freedirs(conn);
|
||||||
freedirs(conn);
|
return CURLE_OUT_OF_MEMORY;
|
||||||
return CURLE_OUT_OF_MEMORY;
|
}
|
||||||
|
if (isBadFtpString(ftpc->dirs[ftpc->dirdepth])) {
|
||||||
|
free(ftpc->dirs[ftpc->dirdepth]);
|
||||||
|
freedirs(conn);
|
||||||
|
return CURLE_URL_MALFORMAT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isBadFtpString(ftpc->dirs[ftpc->dirdepth])) {
|
else {
|
||||||
free(ftpc->dirs[ftpc->dirdepth]);
|
cur_pos = slash_pos + 1; /* jump to the rest of the string */
|
||||||
freedirs(conn);
|
continue;
|
||||||
return CURLE_URL_MALFORMAT;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
cur_pos = slash_pos + 1; /* jump to the rest of the string */
|
cur_pos = slash_pos + 1; /* jump to the rest of the string */
|
||||||
continue;
|
if(++ftpc->dirdepth >= ftpc->diralloc) {
|
||||||
}
|
/* enlarge array */
|
||||||
|
char *bigger;
|
||||||
cur_pos = slash_pos + 1; /* jump to the rest of the string */
|
ftpc->diralloc *= 2; /* double the size each time */
|
||||||
if(++ftpc->dirdepth >= ftpc->diralloc) {
|
bigger = realloc(ftpc->dirs, ftpc->diralloc * sizeof(ftpc->dirs[0]));
|
||||||
/* enlarge array */
|
if(!bigger) {
|
||||||
char *bigger;
|
freedirs(conn);
|
||||||
ftpc->diralloc *= 2; /* double the size each time */
|
return CURLE_OUT_OF_MEMORY;
|
||||||
bigger = realloc(ftpc->dirs, ftpc->diralloc * sizeof(ftpc->dirs[0]));
|
}
|
||||||
if(!bigger) {
|
ftpc->dirs = (char **)bigger;
|
||||||
freedirs(conn);
|
}
|
||||||
return CURLE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
ftpc->dirs = (char **)bigger;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ftp->file = cur_pos; /* the rest is the file name */
|
ftp->file = cur_pos; /* the rest is the file name */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user