【问题标题】:can't download github project with curl command无法使用 curl 命令下载 github 项目
【发布时间】:2013-04-22 02:00:18
【问题描述】:

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

但是,我无法下载。发生错误并说:

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.

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

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

【问题讨论】:

    标签: bash curl github download command


    【解决方案1】:
    curl -L -O https://github.com/ziyaddin/xampp/archive/master.zip
    
    • 你必须使用https://
    • 您必须使用 -L 来跟踪重定向

    【讨论】:

      【解决方案2】:

      您还可以下载tarball (*.tar.gz):

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

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

      • Ss - 使用静默模式,但显示错误(如果有)
      • k - 使用不安全 SSL 连接而不检查 TLS 证书。

      【讨论】:

      • 为什么要使用-k
      • 因为证书可能过期、无效、自签名,或者连接是通过代理建立的,或者您可能没有(不想)拥有证书。否则,您必须使用--cacert 指定它,具体取决于您的操作系统和设置。见herehere
      • libcurl 正在验证的是服务器端证书。除非您使用自签名证书访问本地服务器,否则不应使用 -k,因为它会使您的连接本质上不安全并且容易受到中间人攻击。
      【解决方案3】:
      $ curl -I http://github.com/ziyaddin/xampp/archive/master.zip HTTP/1.1 301 永久移动 服务器:GitHub.com 日期:2013 年 4 月 28 日星期日 09:24:53 GMT 内容类型:文本/html 内容长度:178 连接:关闭 位置:https://github.com/ziyaddin/xampp/archive/master.zip 变化:接受编码

      ...因此,如果您想遵循 HTTP 重定向,则需要使用 -L。或者只是阅读 Steven Penny 的回答...

      【讨论】:

        【解决方案4】:

        curl -JLO "https://github.com/tada/pljava/archive/V1_6_2.zip"

        -J, --remote-header-name 使用标头提供的文件名 (H)。
        -L, --location 跟随重定向 (H)。
        -O, --remote-name 将输出写入名为远程文件的文件。

        要点Reference

        【讨论】:

          【解决方案5】:

          上述答案中没有提到的一件事是如果您有一个非常大的文件,当您转到 GitHub 存储库中的该文件时,您会看到一条消息:

          (Sorry about that, but we can’t show files that are this big right now.)
          

          要下载这么大的文件,需要在 ?raw=true 的 URL 中添加一个参数,如以下 curl 命令示例所示:

          curl -L https://github.com/opengenpos/buildproducts/blob/main/GenPOS_rel_02_03_01_013.exe?raw=true >jkjk.exe
          

          这会在 Windows 命令外壳窗口中产生以下输出:

          C:\Users\rickc\Documents>curl -L https://github.com/opengenpos/buildproducts/blob/main/GenPOS_rel_02_03_01_013.exe?raw=true >jkjk.exe
            % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                           Dload  Upload   Total   Spent    Left  Speed
          100   146  100   146    0     0    146      0  0:00:01 --:--:--  0:00:01   491
          100   157  100   157    0     0    157      0  0:00:01 --:--:--  0:00:01  153k
          100 15.7M  100 15.7M    0     0  15.7M      0  0:00:01  0:00:01 --:--:-- 12.7M
          
          C:\Users\rickc\Documents>
          

          文件被下载到名为jkjk.exe的本地文件中。

          注意:Windows 10 现在同时具有tarcurl 作为标准命令,现在请参阅Tar and Curl Come to Windows!

          从 Insider Build 17063 开始,我们引入了两个命令行 Windows 工具链的工具:curlbsdtar。已经很久了 时间到了,我知道。我们想赞扬那些 创建和维护 bsdtarcurl — 很棒的开源工具 每天被数百万人使用。我们来看两个 这些工具将使在 Windows 上进行开发的有效方式 更好的体验。

          【讨论】:

            猜你喜欢
            • 2022-10-15
            • 2021-05-06
            • 1970-01-01
            • 2015-12-16
            • 1970-01-01
            • 1970-01-01
            • 2014-06-14
            • 2011-08-10
            • 2019-05-30
            相关资源
            最近更新 更多