Curl command file utility supports for downloading and uploading files. Curl is useful for many works with system administration, web development for calling web services, etc. In this tutorial, we are providing 5 frequently used curl commands to download files from remote servers.
1. Simple curl command to download file
To download a file using curl use the following syntax. -O is used for saving files on the local system with the same name on the remote system.
curl -O http://example.com/download/myfile.zip
2. Curl download file and save with different name
You can also save the downloaded file with a different name on the local machine. Use -o
followed by the new file name to download and save files with a different name.
curl -o localname.zip http://example.com/download/myfile.zip
3. Curl to Download Multiple Files
Curl also provides an option to download multiple files simultaneously. To download multiple files at once using the following syntax. All files will be saved with original file names.
curl -O http://example.com/myfile.zip -O http://example.com/myfile2.zip
4. Use Login Credential with Curl Download
Some of the remote resources required authentication to download any file. Curl also allows you to provide authentication details to authorize requests. You can pass login credentials using -u
option for HTTP for FTP requests, like:
curl -u user:password -O http://example.com/myfile.zip
curl -u ftpuser:ftppassword -O ftp://ftp.example.com/myfile.zip
5. Curl download file via proxy
If the server file is only available through a proxy server, or you want to use a proxy for downloading files, Use -x followed by a proxy address and port to download the file via a proxy server.
curl -x "my.proxy.com:3128" -O http://example.net/myfile.zip
Conclusion
Curl is a useful utility to create GET, POST, HEADER, and many other requests to remote servers. Even it is helpful for downloading remote files quickly like wget. This tutorial 5 examples of the curl commands for downloading files from a remote server.
5 Comments
how to download file to different directory using curl.
Use -o with curl command to save file in other directory. Like:
I don’t know who you are but THANK YOU!!!!!!!!!!!!!!!
Hi ,
/usr/bin/curl”,”-k”,”-u”,userName+”:”+password,”\””+hostIP+”\””,”-o” ,csvDownloadPath+”ggggg.csv”
I am using this command , where i am doing wrong, we are not getting any error in logs, running this command in java ,on linux server.
try{
ProcessBuilder pb = new ProcessBuilder(“/usr/bin/curl”,”-k”,”-u”,userName+”:”+password,”\””+hostIP+”\””,”-o” ,csvDownloadPath+”ggggg.csv”);
Process p = pb.start();
InputStream is = p.getInputStream();
System.out.println(“command running “);
}
catch(Exception e){
e.printStackTrace();
System.out.println(“command running through “);
Actually running this…
plz guide me , Thanks In advance