1
0
mirror of https://github.com/moparisthebest/curl synced 2025-02-28 09:21:50 -05:00

FTP: remove trailing slash from path for LIST/MLSD

Closes #4348
This commit is contained in:
Zenju 2019-09-13 17:32:04 +02:00 committed by Daniel Stenberg
parent ac58c51b29
commit 1c02a4e874
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
5 changed files with 12 additions and 13 deletions

View File

@ -1446,20 +1446,19 @@ static CURLcode ftp_state_list(struct connectdata *conn)
The other ftp_filemethods will CWD into dir/dir/ first and
then just do LIST (in that case: nothing to do here)
*/
char *cmd, *lstArg, *slashPos;
char *cmd, *lstArg;
const char *inpath = ftp->path;
lstArg = NULL;
if((data->set.ftp_filemethod == FTPFILE_NOCWD) &&
inpath && inpath[0] && strchr(inpath, '/')) {
size_t n = strlen(inpath);
/* chop off the file part if format is dir/file
otherwise remove the trailing slash for dir/dir/
and full paths like %2f/ except for / */
size_t n = strrchr(inpath, '/') - inpath;
if(n == 0)
++n;
/* Check if path does not end with /, as then we cut off the file part */
if(inpath[n - 1] != '/') {
/* chop off the file part if format is dir/dir/file */
slashPos = strrchr(inpath, '/');
n = slashPos - inpath;
}
result = Curl_urldecode(data, inpath, n, &lstArg, NULL, TRUE);
if(result)
return result;

View File

@ -49,9 +49,9 @@ PASS ftp@example.com
PWD
EPSV
TYPE A
LIST /list/this/path/1010/
LIST /list/this/path/1010
EPSV
LIST /list/this/path/1010/
LIST /list/this/path/1010
QUIT
</protocol>
</verify>

View File

@ -57,7 +57,7 @@ TYPE A
LIST
CWD /
EPSV
LIST list/this/path/1149/
LIST list/this/path/1149
QUIT
</protocol>
</verify>

View File

@ -47,7 +47,7 @@ PASS ftp@example.com
PWD
EPSV
TYPE A
LIST fir#t/third/244/
LIST fir#t/third/244
QUIT
</protocol>
</verify>

View File

@ -64,7 +64,7 @@ SYST
CWD /
EPSV
TYPE A
LIST path/to/the/file/539./
LIST path/to/the/file/539.
QUIT
</protocol>
</verify>