curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: sftp working with option CURLOPT_DIRLISTONLY

From: Daniel Stenberg via curl-library <curl-library_at_cool.haxx.se>
Date: Tue, 12 Mar 2019 12:20:22 +0100 (CET)

On Tue, 12 Mar 2019, 胡德鹏 via curl-library wrote:

> curl_easy_setopt(curl,CURLOPT_USERPWD, "user:password");
> curl_easy_setopt(curl, CURLOPT_URL, "sftp://192.168.0.100:22/home/user/inbound/");
> curl_easy_setopt(curl, CURLOPT_FTPLISTONLY, 1);
> curl_easy_setopt(curl,CURLOPT_CUSTOMREQUEST, "nlst");
> curl_easy_perform(curl);

First let me emphasize that CURLOPT_CUSTOMREQUEST is a pretty strong way of
saying to curl that "hey, I know what I'm doing and I'm telling you to use
this no matter what you think".

> set "CURLOPT_FTPLISTONLY" to "1":

This option is actually called CURLOPT_DIRLISTONLY these days (since 7.16.4)
since it works for more protocols than just FTP.

> with request "nlst", both ftp and sftp only returns file names,

So why do you set CURLOPT_CUSTOMREQUEST? It also doesn't have any effect on
SFTP transfers - which is good for you here since "nlst" isn't a known SFTP
instruction.

By setting this option you tell curl you know better and that it should use
what you tell it. That can very well override or work against other options,
like in this case.

CURLOPT_DIRLISTONLY alone will make curl use list or nslt with FTP.

> but for the request "list", ftp will return the file details including
> permission and size, and for sftp still only return file name.

That's what "list" does to a FTP server. Again it won't change the SFTP
transfer.

> Seems sftp does not obey the ftp command

It does not obey "customrequest", that's correct but that's mostly because
nobody has come up with a good use for it there so we haven't implemented
that...

> and ftp does not obey the value of option "CURLOPT_FTPLISTONLY".

It does, if you just let it!

-- 
  / daniel.haxx.se

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-03-12