簡體   English   中英

無法使用 curl 命令下載 github 項目

[英]can't download github project with curl command

我使用“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 命令從第一個鏈接下載?

curl -L -O https://github.com/ziyaddin/xampp/archive/master.zip
  • 您必須使用https://
  • 您必須使用-L來跟蹤重定向

您還可以使用以下命令下載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 證書。
$ 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

...所以如果您想遵循 HTTP 重定向,則需要使用-L 或者只是閱讀史蒂文佩尼的回答......

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

-J, --remote-header-name 使用標頭提供的文件名 (H)。
-L, --location 跟隨重定向 (H)。
-O, --remote-name 將輸出寫入名為遠程文件的文件。

要點參考

上述答案中沒有提到的一件事是,如果您有一個非常大的文件,當您轉到 GitHub 存儲庫中的該文件時,您會看到一條消息:

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

來自 GitHub 的注釋屏幕截圖,該文件太大而無法顯示

要下載這樣的文件,需要向?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 和 Curl Come to Windows! ):

從 Insider Build 17063 開始,我們向 Windows 工具鏈引入了兩個命令行工具: curlbsdtar 已經很長時間了,我知道。 我們要bsdtar創建和維護bsdtarcurl的人們——每天有數百萬人使用這些很棒的開源工具。 讓我們來看看這些工具將使在 Windows 上開發獲得更好體驗的兩種有影響的方式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM