使用curl下载文件时如何保存远程文件名 [英] How do I preserve the remote filename when Downloading a file using curl
问题描述
可能重复:
如何使用响应头文件名和cURL保存文件
我需要下载成千上万种格式的图像
I need to download many thousands of images in the format
http://oregondigital.org/cgi-bin/showfile.exe?CISOROOT=/棒球&CISOPTR = 0
如果将该链接粘贴到浏览器中,它将尝试下载名为1.jp2的文件
If you paste that link in a browser, it tries to download a file named 1.jp2
我想用curl来做同样的事情。但是,当我运行
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 '
文件名报告为404.txt,您可以下载该文件名,并查看它实际上是我想要的文件。我不能使用-O选项,因为分配给文件的名称不好,并且出于技术原因,我需要在系统上使用实际名称。
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.
如何获得curl下载我在浏览器中可以顺利找到的相同文件的信息?谢谢。
How do I get curl to download the same file I have no trouble retrieving in my browser? Thanks.
推荐答案
解决方案是使用 -O -J
-O, --remote-name Write output to a file named as the remote file
-J, --remote-header-name Use the header-provided filename
所以...
curl -O -J 'http://oregondigital.org/cgi-bin/showfile.exe?CISOROOT=/baseball&CISOPTR=0'
我必须升级CURL。我有7.19版,但不支持-J,但有7.22版(最新)。
I had to upgrade my CURL. I had v 7.19 which doesn't support -J but 7.22 (which is the latest) does.
这篇关于使用curl下载文件时如何保存远程文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!