cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_easy_perform with CURLOPT_NOBODY = 1 returns 0 when ftp file does not exist.

From: Carlos Alloatti <calloatti_at_gmail.com>
Date: Mon, 29 Sep 2008 00:17:57 -0300

On Sun, Sep 28, 2008 at 10:47 PM, Dan Fandrich <dan_at_coneharvesters.com> wrote:
> On Sun, Sep 28, 2008 at 01:25:34PM -0300, Carlos Alloatti wrote:
>> When calling curl_easy_perform with CURLOPT_NOBODY set to 1, setting
>> CURLOPT_URL to a non-existing file in an FTP server, the return value
>> is 0.
>>
>> I am using this to latter get the file size with
>> CURLINFO_CONTENT_LENGTH_DOWNLOAD.
>>
>> The returned file size is -1 in this case, but maybe curl_easy_perform
>> should not return 0, but something else, like
>> CURLE_REMOTE_FILE_NOT_FOUND
>>
>> Under the same circumstances, with CURLOPT_NOBODY set to 0, the return
>> value is 19, CURLE_FTP_COULDNT_RETR_FILE
>>
>> Sorry I cannot provide repro code, I am actually wrapping libcurl in a
>> Visual FoxPro class, and I know the Visual FoxPro code will be useless
>> in this case.
>
> I tried this using the curl command-line client to try to reproduce this:
>
> curl ftp://ftp.mozilla.org/invalid-file
> curl -I ftp://ftp.mozilla.org/invalid-file
>
> and in both cases got error 19, CURLE_FTP_COULDNT_RETR_FILE.
>

Dan,

thank you for your response and for taking some time to check out my problem.

Please excuse my ignorance, but I don't see the relation between your
test conditions and the problem I described. I had to check out what
the -l option means, since I have only used the libcurl library, and
this is what I could find:

-l/--list-only

"(FTP) When listing an FTP directory, this switch forces a name-only
view. Especially useful if you want to machine-parse the contents of
an FTP directory since the normal directory view doesn't use a
standard look or format."

"This option causes an FTP NLST command to be sent. Some FTP servers
list only files in their response to NLST; they do not include
subdirectories and symbolic links."

As far as I understand, this option is not related to the libcurl
CURLOPT_NOBODY option,

-----
EDIT: Now I realize that you mean I as in India and not l as in Lima!
Not the best font choice on my side I guess. Then I donīt know what is
going on. Anyway I will just leave untouched the rest of this post,
maybe there is something else going on.
-----

By the way, I discovered that if I also set CURLOPT_FILETIME to 1, the
I get the correct result code, since MTDM is called before the SIZE
command, and the MTDM correctly fails. So I 'am doing that as a
workaround now.

Debug information and returned data, four scenarios:

(A) Invalid file, CURLOPT_NOBODY = 1, CURLOPT_FILETIME = 0, returns 0

2 PWD
1 257 "/" is current directory.
0 Entry path is '/'
2 TYPE I
1 200 Type set to I
2 SIZE hamlet.xmls
1 550 File not found
2 REST 0
1 350 Rest supported. Restarting at 0
0 Remembering we are in dir ""
0 Connection #0 to host ftp.secureftp-test.com left intact

Data returned:
Accept-ranges: bytes

--------------------------------------------------

(B) VALID file, CURLOPT_NOBODY = 1, CURLOPT_FILETIME = 0, returns 0

2 PWD
1 257 "/" is current directory.
0 Entry path is '/'
2 TYPE I
1 200 Type set to I
2 SIZE hamlet.xml
1 213 279658
2 REST 0
1 350 Rest supported. Restarting at 0
0 Remembering we are in dir ""
0 Connection #0 to host ftp.secureftp-test.com left intact

Data returned:
Content-Length: 279658
Accept-ranges: bytes

--------------------------------------------------

(C) Invalid file, CURLOPT_NOBODY = 1, CURLOPT_FILETIME = 1, returns 19

2 PWD
1 257 "/" is current directory.
0 Entry path is '/'
2 MDTM hamlet.xmls
1 550 File not found
0 Given file does not exist
0 Remembering we are in dir "hamlet.xmlS"
0 Connection #0 to host ftp.secureftp-test.com left intact
0 FTP: couldn't retrieve (RETR failed) the specified file

Data returned:
NO DATA RETURNED

--------------------------------------------------

(D) VALID file, CURLOPT_NOBODY = 1, CURLOPT_FILETIME = 1, returns 0

2 PWD
1 257 "/" is current directory.
0 Entry path is '/'
2 MDTM hamlet.xml
1 213 20070625134931
2 TYPE I
1 200 Type set to I
2 SIZE hamlet.xml
1 213 279658
2 REST 0
1 350 Rest supported. Restarting at 0
0 Remembering we are in dir ""
0 Connection #0 to host ftp.secureftp-test.com left intact

Data returned:
Last-Modified: Mon, 25 Jun 2007 13:49:31 GMT
Content-Length: 279658
Accept-ranges: bytes

I may be wrong of course, and for shure there must be something that
I' am not seeing, after all, I have been playing with the libcurl
library for about week only.

-- 
Carlos Alloatti
Received on 2008-09-29