Discussion:
url malformed error with simple curl usage
Scott Haneda
2010-03-20 03:47:59 UTC
Permalink
Hello curl users,
This has bothered me in my usage (probably incorrect) for a long time.

Taking an image at a resource:
Loading Image...

I want to download that image, or compressed file, iso, whatever.

The man page states I have two options for this:
-o/--output <file>
-O/--remote-name

I would like to have the file downloaded and maintain the filename. According to the man page that means that -o is out, but -O is in:

-O/--remote-name
The remote file name to use for saving is extracted from the
given URL, nothing else.

$cd ~/Downloads/
$curl -O http://www.google.com/intl/en_ALL/images/logo.gif
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 8558 100 8558 0 0 49177 0 --:--:-- --:--:-- --:--:-- 149k

$ls -la logo.gif
-rw-r--r-- 1 me-user staff 8558 Mar 19 20:35 logo.gif
$pwd
~/Downloads

That worked; downloaded the file to the current working directory and kept the file name. But what if I want to download the file to some other location?

$curl http://www.google.com/intl/en_ALL/images/logo.gif -O ~/Desktop
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 8558 100 8558 0 0 62538 0 --:--:-- --:--:-- --:--:-- 146k
curl: (3) <url> malformed

I have tried several variations, none of which I can get to work. The best I can do is:
$cd ~/Someplace; curl -O http://www.google.com/intl/en_ALL/images/logo.gif

Is this not possible in one command?
Thank you for any pointers.
--
Scott * If you contact me off list replace talklists@ with scott@ *

-------------------------------------------------------------------
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
Kamil Dudka
2010-03-20 08:11:06 UTC
Permalink
Post by Scott Haneda
That worked; downloaded the file to the current working directory and kept
the file name. But what if I want to download the file to some other
location?
$curl http://www.google.com/intl/en_ALL/images/logo.gif -O ~/Desktop
% Total % Received % Xferd Average Speed Time Time Time
Current Dload Upload Total Spent Left Speed 100 8558 100 8558
0 0 62538 0 --:--:-- --:--:-- --:--:-- 146k curl: (3) <url>
malformed
You just mixed it up. '-O' parses the file name from URL, thus take no extra
argument. Then the '~/Desktop' is treated as second URL. If you want to
specify the file name manulally, you want to use '-o', which takes an
argument.

Kamil
-------------------------------------------------------------------
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
Scott Haneda
2010-03-20 19:00:46 UTC
Permalink
Post by Kamil Dudka
Post by Scott Haneda
That worked; downloaded the file to the current working directory and kept
the file name. But what if I want to download the file to some other
location?
$curl http://www.google.com/intl/en_ALL/images/logo.gif -O ~/Desktop
% Total % Received % Xferd Average Speed Time Time Time
Current Dload Upload Total Spent Left Speed 100 8558 100 8558
0 0 62538 0 --:--:-- --:--:-- --:--:-- 146k curl: (3) <url>
malformed
You just mixed it up. '-O' parses the file name from URL, thus take no extra
argument. Then the '~/Desktop' is treated as second URL. If you want to
specify the file name manulally, you want to use '-o', which takes an
argument.
So it is not possible to do what I desire, which is to use -O to parse the filename from the URL, and set an alternate save destination in the same command. curl will always save with -O to the cwd?

If that is the case, that is great to know, as I now know I will simply have to cd to the preferred directory first.

Thank you all
--
Scott * If you contact me off list replace talklists@ with scott@ *

-------------------------------------------------------------------
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
Kamil Dudka
2010-03-20 19:47:00 UTC
Permalink
Post by Scott Haneda
So it is not possible to do what I desire, which is to use -O to parse the
filename from the URL, and set an alternate save destination in the same
command. curl will always save with -O to the cwd?
AFAIK, yes.
Post by Scott Haneda
If that is the case, that is great to know, as I now know I will simply
have to cd to the preferred directory first.
Sure, doing so in a subshell might be also good idea:

$ (cd ~/Desktop && curl -O ...)

Kamil
-------------------------------------------------------------------
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
Doug McNutt
2010-03-20 20:34:26 UTC
Permalink
Post by Kamil Dudka
$ (cd ~/Desktop && curl -O ...)
** How about making curl behave more like cp or scp when the specified destination is a directory?

curl http://something .com/with/subdirectories/wanted_file -o $HOME/Downloads/

really ought never to replace the Downloads directory with a file but actually I think it will unless it encounters permission problems on the directory.

scp or cp will create a new file wanted_file in HOME/Downloads/. No o or O required.

** There is a provision for transmitting multiple files with [ ] grep-like matching which I always have to look up in the man page:"

curl http://something .com/with/subdirectories/[wanted_file] -o $HOME/Downloads/[1]

just might work.

** Of course one can define a shell variable that is the file name.
#!csh
set what=wanted_file
curl http://something .com/with/subdirectories/$what -o $HOME/Downloads/$what

If you're going to do other similar downloads saving that script in a shell-enabled text editor (BBEdit, MPW, gedit) will allow repeated executions without changing the curl command line.
--
--> A fair tax is one that you pay but I don't <--
-------------------------------------------------------------------
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
Daniel Stenberg
2010-03-20 21:48:17 UTC
Permalink
Post by Doug McNutt
** How about making curl behave more like cp or scp when the specified
destination is a directory?
curl http://example.com/with/subdirectories/wanted_file -o
$HOME/Downloads/
I think could learn to like that, and it wouldn't cause any backwards
compatibility problems since the above command line won't really work with a
current curl.
Post by Doug McNutt
scp or cp will create a new file wanted_file in HOME/Downloads/. No o or O required.
I view curl to be more like 'cat' than 'cp' though. That's one reason why it
sends the data to stdout by default.
Post by Doug McNutt
** There is a provision for transmitting multiple files with [ ] grep-like
matching which I always have to look up in the man page:"
curl http://example.com/with/subdirectories/[wanted_file] -o
$HOME/Downloads/[1]
just might work.
Yes, at least if written like this:

curl http://example.com/with/subdirectories/{wanted_file} -o
$HOME/Downloads/#1

(I changed the URLs to use example.com which is made for exactly that.)
--
/ 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
Loading...