Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I preserve the remote filename when Downloading a file using curl [duplicate]

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.

like image 998
Kyle Banerjee Avatar asked Sep 16 '11 23:09

Kyle Banerjee


People also ask

How do I use curl command to download a file?

How to download a file with curl command. The basic syntax: Grab file with curl run: $ curl https://your-domain/file.pdf. Get file using ftp or sftp protocol: $ curl ftp://ftp-your-domain-name/file.tar.gz.

Does curl save the data to a file by default or does it just output to the terminal?

1M is 1048576 bytes. curl displays this data to the terminal by default, so if you invoke curl to do an operation and it is about to write data to the terminal, it disables the progress meter as otherwise it would mess up the output mixing progress meter and response data.

How do I download files using curl Windows?

To download a file with Curl, use the --output or -o command-line option. This option allows you to save the downloaded file to a local drive under the specified name. If you want the uploaded file to be saved under the same name as in the URL, use the --remote-name or -O command line option.

Where does curl save to?

Consequentially, the file will be saved in the current working directory. If you want the file saved in a different directory, make sure you change current working directory before you invoke curl with the -O, --remote-name flag! There is no URL decoding done on the file name.


1 Answers

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.

like image 55
Yevgeny Simkin Avatar answered Sep 25 '22 16:09

Yevgeny Simkin