How do I save a file using the response header filename with cURL?

后端 未结 4 1907
不思量自难忘°
不思量自难忘° 2020-12-08 01:59

This question relates to the command line version of cURL.

I\'m trying to download a file from a CGI script.

http://example.com/perl/dl.pl?ID=2


        
相关标签:
4条回答
  • 2020-12-08 02:10

    you can try the -o or -O option.

    0 讨论(0)
  • 2020-12-08 02:14

    if you have a new enough curl (version 7.20.0 or later), -J/--remote-header-name is what you want.

    You use -J in conjunction with -O, which makes curl use the file name part from the URL as its primary way to name the output file and then if there is a Content-disposition: header in the response, curl will use that name instead.

    0 讨论(0)
  • 2020-12-08 02:14

    curl -OJ gave me segmentation fault: 11 error when attempting to download multiple URLs at once.

    Instead, I used wget. The latest version supports HTTP Content-Disposition headers, which often contain filename information.

    wget --content-disposition http://example.com/download/url
    
    0 讨论(0)
  • 2020-12-08 02:23
    curl http://example.com/dl.php?file=3123123 -O -J
    

    if server uses redirection use these:

    --location-trusted
    --max-redirs 10
    
    0 讨论(0)
提交回复
热议问题