cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Inconsistent request with dubious return code

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 18 Jul 2014 23:18:15 +0200 (CEST)

On Thu, 17 Jul 2014, gilles wrote:

> I was testing an upload to a FTP server under the same file name, such as:
>
> curl -T uploadfile -u user:passwd ftp://ftp.upload.com/
>
> But I mistakenly wrote -O instead of -T.
>
> So my request is inconsistent because -O is for a download and I specified
> no file name.

Not only that. You then also provided 'uploadfile' after the -O, which then
gets interpreted as a URL. In your case it'll try to access a host named
'uploadfile'. Most likely you don't have such a host.

> I got "Remote file name has no length!" which is ok.

Yes, because the file name part of the URL 'uploadfile' is non-existant.

> And curl returned a directory listing instead [should programs
> interpret an incorrectly formed request?].

Not instead, additionally. Because you provided two URLs so after it used the
-O and didn't get the download of 'uploadfile' into a file, it moved on to the
next URL you provided: ftp://ftp.upload.com/ and with the single -O already
parsed there was no more instruction on how to deliver the transfer so it
sends it to stdout. And since you provided a FTP URL that ends with a slash,
it means you ask for a directory listing.

> But the return code is 0!

Because the last transfer worked fine.

> I would definitely expect to have a meaningful return code in this case,
> because the intended action was not achieved.

curl interpreted the command line differently than you meant it. I don't see
how curl could've done much differently in this situation... One option would
be to fail immediately on the first URL that fails, but that's not something
we've ever done so we can't easily introduce such a behavior now without
breaking a lot of existing scripts.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2014-07-18