Skip to content

FTP with CURLOPT_NOBODY different behavior when performing on non-existing files #5953

Closed
@Togtja

Description

@Togtja

I did this

I tried to make a function in libcurl that checks if a file exist on server:

curl_easy_setopt(curl, CURLOPT_URL, "ftp://user:pwd@host/fakefile.txt");
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);

CURLcode res = curl_easy_perform(curl);
//res is CURLE_OK

However, because I use the CURLOPT_NOBODY option, perform returns CURLE_OK (If I don't use the no body option it return CURLE_REMOTE_FILE_NOT_FOUND) . However, on SFTP calls in reruns as I expect:

curl_easy_setopt(curl, CURLOPT_URL, "sftp://user:pwd@host/fakefile.txt");
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);

CURLcode res = curl_easy_perform(curl);
//res is CURLE_REMOTE_FILE_NOT_FOUND

I expected the following

I expect them both to return CURLE_REMOTE_FILE_NOT_FOUND or at least have the same behaviour

curl/libcurl version

7.72.0

curl 7.72.0 (Linux) libcurl/7.72.0 OpenSSL/1.1.1g zlib/1.2.11 libssh2/1.9.0_DEV
Release-Date: 2020-08-19
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS HTTPS-proxy IPv6 Largefile libz NTLM SSL UnixSockets

operating system

Linux togtja-ubuntu 5.4.0-47-generic #51~18.04.1-Ubuntu SMP Sat Sep 5 14:35:50 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Activity

bagder

bagder commented on Sep 11, 2020

@bagder
Member

I think if you also do:

  curl_easy_setopt(hnd, CURLOPT_FILETIME, 1L);

... it might actually do what you expected it. As a work-around.

added a commit that references this issue on Sep 12, 2020
3cda822
bagder

bagder commented on Sep 12, 2020

@bagder
Member

@Togtja if you enable VERBOSE for your scenario, do you see the SIZE command get a 550 back? that's what I'm assuming and what my suggested fix in #5957 acts on.

self-assigned this
on Sep 13, 2020
Togtja

Togtja commented on Sep 14, 2020

@Togtja
Author

setting curl_easy_setopt(curl, CURLOPT_FILETIME, 1L); returns CURLE_FTP_COULDNT_RETR_FILE

With verbose without setting CURLOPT_FILETIME, it does indeed return 550 Could not get file size

After compiling #5957 It does indeed now actually return CURLE_FTP_COULDNT_RETR_FILE for me. Is there a big difference between CURLE_FTP_COULDNT_RETR_FILE and CURLE_REMOTE_FILE_NOT_FOUND?

bagder

bagder commented on Sep 14, 2020

@bagder
Member

Hm. I think I was too quick and you're right. It should rather use CURLE_REMOTE_FILE_NOT_FOUND for this. I'll amend my PR!

added a commit that references this issue on Sep 14, 2020
9d0992e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @bagder@Togtja

    Issue actions

      FTP with CURLOPT_NOBODY different behavior when performing on non-existing files · Issue #5953 · curl/curl