Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

curl

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 

Using a browser the filename comes up as remotefilename.gz. cURL wants to save the file as dl.pl?ID=2.

How do I get cURL to save to a file with the filename from the response header?

like image 808
John Avatar asked Apr 23 '10 12:04

John


People also ask

How do I save a file in curl?

Grab file with curl run: $ curl https://your-domain/file.pdf. Get file using ftp or sftp protocol: $ curl ftp://ftp-your-domain-name/file.tar.gz. You can set the output file name while downloading file with the curl, execute: $ curl -o file.

How do you get the curl response header?

We can use curl -v or curl -verbose to display the request headers and response headers in the cURL command. The > lines are request headers .

How do I download a tar file with curl?

To download you just need to use the basic curl command but add your username and password like this curl --user username:password -o filename. tar. gz ftp://domain.com/directory/filename.tar.gz . To upload you need to use both the –user option and the -T option as follows.

Where does curl download to?

Consequentially, the file will be saved in the current working directory. If you want the file saved in a different directory, make sure you change current working directory before you invoke curl with the -O, --remote-name flag!


1 Answers

-J/--remote-header-name is the option 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.

like image 54
Daniel Stenberg Avatar answered Oct 05 '22 06:10

Daniel Stenberg