开发者

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

开发者 https://www.devze.com 2023-04-05 05:57 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How do I save a file using the response header filename with cURL
This question already has answers here: Closed 11 years ago.

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.


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.


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"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号