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?
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.
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 .
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.
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!
-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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With