本文介绍了在以下位置后卷曲以获取远程文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 curl 下载文件时,我如何跟踪链接位置并将其用作输出文件名(事先不知道远程文件名)?

When downloading a file using curl, how would I follow a link location and use that for the output filename (without knowing the remote filename in advance)?

例如,如果单击下面的链接,您将下载名为pythoncomplete.vim"的文件.但是使用 curl 的 -O 和 -L 选项,文件名只是原始的远程名称,一个笨拙的download_script.php?src_id=10872."

For example, if one clicks on the link below, you would download a filenamed "pythoncomplete.vim." However using curl's -O and -L options, the filename is simply the original remote-name, a clumsy "download_script.php?src_id=10872."

curl -O -L http://www.vim.org/scripts/download_script.php?src_id=10872

为了下载具有正确文件名的文件,您必须提前知道文件名:

In order to download the file with the correct filename you would have to know the name of the file in advance:

curl -o pythoncomplete.vim -L http://www.vim.org/scripts/download_script.php?src_id=10872

如果您可以在不知道名称的情况下下载文件,那就太好了,如果没有,还有其他方法可以通过命令行快速拉下重定向的文件吗?

It would be excellent if you could download the file without knowing the name in advance, and if not, is there another way to quickly pull down a redirected file via command line?

推荐答案

远程端使用 Content-Disposition 标头发送文件名.

The remote side sends the filename using the Content-Disposition header.

curl 7.21.2 或更新版本会自动执行此操作.

curl 7.21.2 or newer does this automatically if you specify --remote-header-name / -J.

curl -O -J -L $url

这篇关于在以下位置后卷曲以获取远程文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 12:05