如何使用curl下载文件

Ale*_*ory 22 macos terminal command-line curl

我在Mac OS X上,无法弄清楚如何通过命令行从URL下载文件.它来自一个静态页面,所以我想复制下载链接,然后使用curl就可以做到这一点,但事实并非如此.

我引用了这个StackOverflow问题但是没有用.我也引用了这篇文章也没用.

我尝试过的:

curl -o https://github.com/jdfwarrior/Workflows.git
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
Run Code Online (Sandbox Code Playgroud)

.

wget -r -np -l 1 -A zip https://github.com/jdfwarrior/Workflows.git
zsh: command not found: wget
Run Code Online (Sandbox Code Playgroud)

如何通过命令行下载文件?

jfl*_*fly 27

-o --output选项意味着curl将输出写入你指定的文件而不是stdout,你把url放在后面-o,所以curl认为url是一个要写的文件而没有指定url.你需要一个文件名-o,然后是网址.由于url是基于HTTPS的,因此您可能还需要以下-k选项:

curl -o ./filename -k https://github.com/jdfwarrior/Workflows.git
Run Code Online (Sandbox Code Playgroud)

并且OS X上默认不提供wget.


小智 6

curl -OL https://github.com/jdfwarrior/Workflows.git
Run Code Online (Sandbox Code Playgroud)

-O:此选项用于将输出写入到我们获得的名称类似于远程文件的文件中。在这种卷曲中,该文件将是Workflow.git

-L:如果服务器报告所请求的页面已移动到其他位置(由Location:标头和3XX响应代码指示),则使用此选项,此选项将使curl在新位置上重做请求。

参考:curl手册页

  • 如果无法下载,我建议添加选项 `--fail` 或 `-f` 以使 `curl` 失败(= 以非零返回代码退出)。否则会成功下载错误文档。 (2认同)

Agi*_*ean 5

对于您的问题,最简单的解决方案是保留原始文件名。在这种情况下,您只需要使用大写字母o(“-O”)作为选项(而不是零= 0!)。所以看起来像:

curl -O https://github.com/jdfwarrior/Workflows.git
Run Code Online (Sandbox Code Playgroud)