How to download a file using cURL command

cURL is a powerful command-line tool used to transfer data to or from a server. It supports various protocols, including HTTP, HTTPS, FTP, and SFTP, enabling easy downloading directly from the command line.

Save and Save As in cURL.

1. Start by accessing your hosting environment over SSH using a command line tool, if you don’t have one download PuTTY.

2. From here we can start by retrieving a file with cURL, this will display the contents of the file in the terminal window with the following example command.

curl https://www.unlimitedwebhosting.co.uk/assets/images/vps/uwh_vps_hosting_hero.svg
cURL being used in a command line window
cURL

3. Moving on, the command above can be modified with either:

  • -O (Uppercase) – Saves the file with the original name similar to a normal save function. The command itself doesn’t need additional information.
cURL being used with the save feature.
cURL Save
  • -o (Lowercase) – Create a new name for the file acts as a save as function. You will need to add the new filename before the target.
Using cURL with save as feature
cURL Save As

Using cURL with redirects

If the URL has has an redirects add the -L flag to the command, this ensures that cURL follows redirects which is important for some URLS. A good example of this would be http:// to https:// redirects when http is entered with the -L flag it will redirect correctly.

curl -o -L http://unlimitedwebhosting.co.uk/assets/images/vps/uwh_vps_hosting_hero.svg

Using cURL with FTP

Similarly you can use cURL with FTP and SFTP ensure that you add the -u flag if you have authentication enabled. An example command is shown below using FTP, this can be swapped/interchanged with SFTP depending on your preference.

curl -u root:root*password ftp://ftp.yourftpserver.tld/backup.tar.gz