I know how to use wget command to grab files. But, how do you download file using curl command line under Linux / Mac OS X / BSD or Unix like operating systems?
GNU wget is a free utility for non-interactive download of files from the Web. curl is another tool to transfer data from or to a server, using one of the supported protocols such as HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE). The command is designed to work without user interaction. curl offers many features such as:
- Proxy support.
- User authentication.
- FTP upload.
- HTTP post.
- SSL connections.
- Cookies.
- File transfer resume and more.
curl download file
The syntax is as follows to grab (download) files from remote http/ftp server:
curl -o output.file http://server1.cyberciti.biz/file.tar.gz
OR
curl -O http://server1.cyberciti.biz/file.tar.gz
OR
curl --remote-name http://server1.cyberciti.biz/file.tar.gz
You can download a web page and store in a local file as follows:
curl -o nixcraft.html http://www.cyberciti.biz/low.html
You can grab or download multiple files as follows:
curl -O http://www.cyberciti.biz/low.html -O http://bash.cyberciti.biz/dl/581.sh.zip
curl download file from an ssh server
You can grab file securely using from an SSH server using SFTP:
curl -u username sftp://server1.cyberciti.biz/path/to/file.txt
OR (note ~ means your $HOME)
curl -u vivek sftp://home1.cyberciti.biz/~/docs/resume.pdf
You can grab a file from an SSH server using SCP using a private key to authenticate. The syntax is:
curl -u username: --key ~/.ssh/id_rsa --pubkey ~/.ssh/id_rsa.pub scp://home1.cyberciti.biz/~/Videos/rhn_register.ogv
Where,
- -u username - Specify the user name (and optional password) to use for server authentication.
- -u username:password - Specify the user name (and optional password) to use for server authentication.
- --key ~/.ssh/id_rsa - SSL or SSH private key file name. Allows you to provide your private key in this separate file.
- --pubkey ~/.ssh/id_rsa.pub - SSH Public key file name. Allows you to provide your public key in this separate file.
- scp://home1.cyberciti.biz/~/Videos/rhn_register.ogv - Use scp protocol and download file from my home server called home1.cyberciti.biz.
Curl: Download a file using username and password
The syntax is as follows to grab a file using ftp username and password:
curl ftp://username:passwd@ftp1.cyberciti.biz:21/path/to/backup.tar.gz
OR
curl -u UserName:PassWord ftp://ftp1.cyberciti.biz:21/backups/07/07/2012/mysql.blog.sql.tar.gz
Secure ftp user (ftp with ssl) can pass the --ftp-ssl option to curl command:
curl --ftp-ssl -u UserName:PassWord ftp://ftp1.cyberciti.biz:21/backups/07/07/2012/mysql.blog.sql.tar.gz
HTTP authentication
HTTP user can use the following syntax:
curl http://username:passwd@server1.cyberciti.biz/file/path/data.tar.gz
OR
curl -u Username:Password http://server1.cyberciti.biz/file/path/data.tar.gz
Check out related media:
See also:
- man page curl
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 3 comments… read them below or add one }
Why the hell would one use curl to do scp, when “scp” exists and is the direct tool?
copy from remote host to “here”
scp user@remote.host:/the/path/to/thefile . <– note the "."
copy from "here" to remote host:
scp file user@remote.host:/the/target/path/
pub key authentication is automatic if there is a key that is acceptable to the server in your .ssh directory.
…just for the sake of argument? :)
A developer can include libcurl and get the ability to scp, http get, etc in their application all in one shot. Or if you are building an embedded system you can get a wide range of capabilities out of one tool which can be very valuable.