【问题标题】:Zip file downloaded via batch file/cmd is corrupted [closed]通过批处理文件/cmd下载的压缩文件已损坏[关闭]
【发布时间】:2021-12-29 13:38:13
【问题描述】:

curl -o ./Makent-files.zip "https://github.com/Mapagmataas/Makent/archive/refs/heads/files.zip" --ssl-no-revoke

下载的 zip 文件已损坏

【问题讨论】:

    标签: batch-file curl cmd


    【解决方案1】:

    我会使用参数“-L”/“--location”来指示 curl 跟随位置。 示例:

    $ curl -L -o ./Makent-files.zip "https://github.com/Mapagmataas/Makent/archive/refs/heads/files.zip"
    
    $ zipinfo Makent-files.zip 
    Archive:  Makent-files.zip
    Zip file size: 9948 bytes, number of entries: 2
    drwx---     0.0 fat        0 bx stor 21-Dec-29 11:20 Makent-files/
    -rw----     0.0 fat   105662 bx defN 21-Dec-29 11:20 Makent-files/Makent.ico
    2 files, 105662 bytes uncompressed, 9626 bytes compressed:  90.9%
    

    摘自 curl 手册页:

          -L, --location
                  (HTTP) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make curl redo the request on the new place. If used  together  with
                  -i,  --include  or -I, --head, headers from all requested pages will be shown. When authentication is used, curl only sends its credentials to the initial host. If a redirect takes curl to a different host, it will not be able to in‐
                  tercept the user+password. See also --location-trusted on how to change this. You can limit the amount of redirects to follow by using the --max-redirs option.
    
                  When curl follows a redirect and if the request is a POST, it will send the following request with a GET if the HTTP response was 301, 302, or 303. If the response code was any other 3xx code, curl will re-send the following  request
                  using the same unmodified method.
    
                  You can tell curl to not change POST requests to GET after a 30x response by using the dedicated options for that: --post301, --post302 and --post303.
    
                  The method set with -X, --request overrides the method curl would otherwise select to use.
    
                  Example:
                   curl -L https://example.com
    

    参考:https://curl.se/docs/manpage.html

    使用示例扩展来自@SomethingDark 的评论的更广泛解释

    # downloading the file without following the location - we are downloading a html file
    $ curl -o ./Makent-files-without-minusL.zip "https://github.com/Mapagmataas/Makent/archive/refs/heads/files.zip"  
    
    # downloading the file with following the location - we are downloading the zip file befind the location redirect.
    $ curl -L -o ./Makent-files-with-minusL.zip "https://github.com/Mapagmataas/Makent/archive/refs/heads/files.zip" 
    
    # one file on your disk is a zip file and the other one the html file
    $ file *
    Makent-files-with-minusL.zip:    Zip archive data, at least v1.0 to extract, compression method=store
    Makent-files-without-minusL.zip: HTML document, ASCII text, with no line terminators
    

    【讨论】:

    • 我不太明白怎么做,但它帮助了我。谢谢本杰明!
    • @Mapagmataas - Github 不直接提供文件;它们存储在单独的服务器上,当您尝试访问文件时,您会被重定向到那里。 curl 默认不重定向,所以你最初只是下载重定向页面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-16
    • 2017-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-28
    相关资源
    最近更新 更多