FTP Bug: wrong dir listing because libcurl remembers wrong CWD #1782

PeterLamare2 opened this Issue Aug 14, 2017 · 1 comment


None yet
2 participants

I think this is caused by the changes in:

Steps to reproduce:
When the first easy handle uses CURLFTPMETHOD_MULTICWD and accesses some path /subfolder, libcurl stores this under ftpc->prevpath.

The easy handle is then reused, but this time using CURLFTPMETHOD_NOCWD, also passing /subfolder as CURLOPT_URL.
Now in ftp.c:: ftp_parse_url_path, there is still this code which does not consider CURLFTPMETHOD

  ftpc->cwddone = FALSE; /* default to not done */

  if(ftpc->prevpath) {
    /* prevpath is "raw" so we convert the input path before we compare the
       strings */
    size_t dlen;
    char *path;
    CURLcode result =
      Curl_urldecode(conn->data, data->state.path, 0, &path, &dlen, FALSE);
    if(result) {
      return result;

    dlen -= ftpc->file?strlen(ftpc->file):0;
    if((dlen == strlen(ftpc->prevpath)) &&
       !strncmp(path, ftpc->prevpath, dlen)) {
      infof(data, "Request has same path as previous transfer\n");
      ftpc->cwddone = TRUE;

Consequence: ftpc->cwddone = TRUE; will be set, which is incorrect for CURLFTPMETHOD_NOCWD, which is supposed to operate on the ftp entry path.

As a result, the CURLFTPMETHOD_NOCWD + "MLSD subfolder" will not find any results, because the working dir is alreay at /subfolder! (consider CURLOPT_CUSTOMREQUEST MLSD)


@bagder bagder added the FTP label Aug 15, 2017

bagder added a commit that referenced this issue Aug 15, 2017


bagder commented Aug 15, 2017

@PeterLamare2 any chance you can try the fix in #1787 just to be sure it fixes the problem for you the way I intended it to?

@bagder bagder closed this in c95eff4 Aug 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment