130

Possible Duplicate:
How do I save a file using the response header filename with cURL

I need to download many thousands of images in the format

http://oregondigital.org/cgi-bin/showfile.exe?CISOROOT=/baseball&CISOPTR=0

If you paste that link in a browser, it tries to download a file named 1.jp2

I want to use curl to do the same. However, when I run

curl -I 'http://oregondigital.org/cgi-bin/showfile.exe?CISOROOT=/baseball&CISOPTR=0'

the filename is reported as 404.txt which you can download and see that it is actually the file I want. I can't use the -O option because the name assigned to the file is no good, and I have technical reasons for needing the actual name used on the system.

How do I get curl to download the same file I have no trouble retrieving in my browser? Thanks.

Community
  • 1
  • 1
Kyle Banerjee
  • 2,554
  • 4
  • 22
  • 30
  • my guess is that this is somehow related to the user-agent of the caller, though I just tried it adding chrome's UA and that didn't help. – Yevgeny Simkin Sep 16 '11 at 23:57

2 Answers2

221

The solution is to use -O -J

-O, --remote-name          Write output to a file named as the remote file  
-J, --remote-header-name   Use the header-provided filename

So...

curl  -O -J  'http://oregondigital.org/cgi-bin/showfile.exe?CISOROOT=/baseball&CISOPTR=0'

I had to upgrade my CURL. I had v 7.19 which doesn't support -J but 7.22 (which is the latest) does.

meetar
  • 7,443
  • 8
  • 42
  • 73
Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236
-9

You can use the -o option can you? eg

 curl  'http://oregondigital.org/cgi-bin/showfile.exe?CISOROOT=/baseball&CISOPTR=[0-9]' -o "#1.jpg"
bash-o-logist
  • 6,665
  • 1
  • 17
  • 14
  • 1
    he says right in his question that he can't use the -O because he doesn't want the file name to be showfile.exe?... etc. Pay Attention! :) – Yevgeny Simkin Sep 17 '11 at 01:42
  • the user can't define the file name in this case... it's coming from the header of the incoming response – Yevgeny Simkin Sep 17 '11 at 05:11
  • 7
    -o lets you set a custom name and more importantly, a custom location for the downloaded file. -O automatically names the file, but also downloads it to the default location (my home folder in my case). So how would I combine the two, and choose where the file gets downloaded, but preserving the name from the server? – l008com Sep 03 '18 at 06:28