bash 无法使用 curl 命令下载 github 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16261100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:17:01  来源:igfitidea点击:

can't download github project with curl command

bashcurlgithubdownloadcommand

提问by Ziyaddin Sadigov

I used "curl -sO" command to download project files from this GitHub project link: http://github.com/ziyaddin/xampp/archive/master.zip

我使用“curl -sO”命令从这个 GitHub 项目链接下载项目文件:http://github.com/ziyaddin/xampp/archive/master.zip

but, I couldn't download. There is error occured and says that:

但是,我无法下载。出现错误并说:

Archive:  /home/ziyaddin/Desktop/master.zip
[/home/ziyaddin/Desktop/master.zip]   End-of-central-directory
signature not found.  Either this file is not   a zipfile, or it
constitutes one disk of a multi-part archive.  In the   latter case
the central directory and zipfile comment will be found on   the last
disk(s) of this archive. zipinfo:  cannot find zipfile directory in
one of /home/ziyaddin/Desktop/master.zip or
          /home/ziyaddin/Desktop/master.zip.zip, and cannot find 
/home/ziyaddin/Desktop/master.zip.ZIP, period.

but I can download this link with curl command: http://cloud.github.com/downloads/pivotal/jasmine/jasmine-standalone-1.3.1.zip

但我可以使用 curl 命令下载此链接:http: //cloud.github.com/downloads/pivotal/jasmine/jasmine-standalone-1.3.1.zip

I think that it is because it is in cloud.github.com. I want to know how can I download from first link with curl command?

我认为是因为它在 cloud.github.com 中。我想知道如何使用 curl 命令从第一个链接下载?

回答by Steven Penny

$ curl -LOk https://github.com/ziyaddin/xampp/archive/master.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   119  100   119    0     0    375      0 --:--:-- --:--:-- --:--:--   388
  0     0    0  1706    0     0   1382      0 --:--:--  0:00:01 --:--:--  333k
  • you must use https://
  • you must use -Lto follow redirects
  • you must use -kif your certificate file is missing
  • 你必须使用 https://
  • 您必须使用-L来跟踪重定向
  • -k如果您的证书文件丢失,您必须使用

回答by not2qubit

You can also download a tarball(*.tar.gz) with:

您还可以使用以下命令下载tarball( *.tar.gz):

curl -LkSs https://api.github.com/repos/ziyaddin/xampp/tarball -o master.tar.gz

or if you use the -Oyou can omit the filename, but then your saved ".tar.gz" file, is named by default to "tarball", so you have to rename it and add the ".tar.gz" filetype postfix. So use the (lowercase) -oas above. The rest:

或者,如果您使用 ,-O您可以省略文件名,但是您保存的“.tar.gz”文件默认命名为“tarball”,因此您必须重命名它并添加“.tar.gz”文件类型后缀。所以使用-o上面的(小写)。其余的部分:

  • Ss- use silent mode, but show errors, if any
  • k- use an insecureSSL connection without checking the TLS cert.
  • Ss- 使用静默模式,但显示错误,如果有的话
  • k- 使用不安全的SSL 连接而不检查 TLS 证书。

回答by Daniel Stenberg

$ curl -I http://github.com/ziyaddin/xampp/archive/master.zip
HTTP/1.1 301 Moved Permanently
Server: GitHub.com
Date: Sun, 28 Apr 2013 09:24:53 GMT
Content-Type: text/html
Content-Length: 178
Connection: close
Location: https://github.com/ziyaddin/xampp/archive/master.zip
Vary: Accept-Encoding

... so you need to use -Lif you want to follow the HTTP redirect. Or just read Steven Penny's answer...

...所以-L如果你想遵循 HTTP 重定向,你需要使用。或者只是阅读史蒂文佩尼的回答......