Linux / Unix curl Command Download File Example

I know how to use wget command to grab files. But, how do you download file using curl command line under a 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:

  1. Proxy support.
  2. User authentication.
  3. FTP upload.
  4. HTTP post.
  5. SSL connections.
  6. Cookies.
  7. 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
curl -O
curl --remote-name

You can download a web page and store in a local file as follows:
curl -o nixcraft.html
You can grab or download multiple files as follows:
curl -O -O

curl download file from an ssh server

You can grab file securely using from an SSH server using SFTP:
curl -u username s
## ~ means your $HOME dir ##
curl -u vivek s

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/ scp://

  • -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/ – SSH Public key file name. Allows you to provide your public key in this separate file.
  • scp:// – Use scp protocol and download file from my home server called

Curl: Download a file using username and password

The syntax is as follows to grab a file using ftp username and password:
curl -u UserName:PassWord
Secure ftp user (ftp with ssl) can pass the –ftp-ssl option to curl command:
curl --ftp-ssl -u UserName:PassWord

HTTP authentication and downloading files with curl

HTTP user can use the following syntax:
curl -u Username:Password

Check out related media:

See also:
  • man page curl

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • Fo Jul 19, 2012 @ 7:13

    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 . <– note the "."

    copy from "here" to remote host:
    scp file

    pub key authentication is automatic if there is a key that is acceptable to the server in your .ssh directory.

    • Kikko Jul 30, 2012 @ 9:14

      …just for the sake of argument? :)

    • Will Aug 2, 2012 @ 1:44

      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.

  • sami Sep 20, 2013 @ 14:34

    i have a problem downloading pdf files using curl command from for the document with an id such as PMC3516508, i used the following command:

    but i don’t get the pdf file for the document.

  • Ryan Sep 3, 2015 @ 15:45

    I would like to know how to download a specific file type using wget or curl from a webpage.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum