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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With