How do I preserve the remote filename when Downloa

2020-05-14 13:11发布

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.

2条回答
Animai°情兽
2楼-- · 2020-05-14 13:55

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"
查看更多
聊天终结者
3楼-- · 2020-05-14 13:56

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.

查看更多
登录 后发表回答