In this tutorial, we will look at curl and wget, how to get started, and most importantly, the differences between them.
What is cURL?
cURL is a free and open-source command-line utility that allows users to transfer data from one remote machine to another with minimal or no user interaction. CURL use is prevalent in devices like routers, printers, phones, tablets, media players, and more.
It supports downloading and uploading using protocols such as HTTP/HTTPS, FTP, SFTP, SCP, IMAP, LDAP/LDAPS, SMB/SMBS, TELNET, POP3, GOPHER, and many, many more.
cURL also provides proxies, resume transfers, user authentication, SSL certificates, and so much more.
What is wget?
GNU Wget, commonly called wget, is a free command-line utility for transferring files using HTTP/HTTPS, FTP, and FTPS. It provides features like recursive downloads, bandwidth control, resumes aborted transfers, background downloads, recursive mirror files and directories, and many more.
How to Install cURL and Wget?
cURL and wget are popular tools readily available in major Linux distributions; if you do not have either tool installed, you use the commands below to install:
Debian/Ubuntu:
sudo apt-get install curl
# install wget
sudo apt-get install wget
Arch/Manjaro:
sudo pacman -S curl
# install wget
sudo pacman -S wget
REHL/CentOS/Fedora:
sudo yum install curl
sudo dnf install curl
# install wget
sudo yum install wget
sudo dnf install wget
How to Use cURL and Wget (Example Use Cases)?
To ensure that you understand the similarities and differences between cURL and wget, it’s good to look at a few examples:
HTTP/HTTPS Protocols:
Both cURL and wget support HTTP and HTTPS protocols. Hence, if we download a website such as linuxhint.com:
curl https://linuxhint.com -o linuxhint.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 256k 0 256k 0 0 166k 0 --:--:-- 0:00:01 --:--:-- 166k
By default, cURL will print the contents of the web resource in the terminal. We use the -o flag to redirect the output to a file.
The following applies to wget:
--2021-06-20 05:09:45-- https://linuxhint.com/
Resolving linuxhint.com (linuxhint.com)... 104.21.58.234, 172.67.209.252, 2606:4700:3033::6815:3aea, ...
Connecting to linuxhint.com (linuxhint.com)|104.21.58.234|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html’
index.html
[ <=> ] 256.25K 506KB/s in 0.5s
2021-06-20 05:09:46 (506 KB/s) - ‘index.html’ saved [262396]
Wget, on the other hand, saves the requested resource to a file.
It is good to note that both tools download the resource. The ls details of the two files show both file sizes.
-rw-rw-r-- 1 linuxhint linuxhint 262396 Jun 19 15:50 index.html
-rw-rw-r-- 1 linuxhint linuxhint 262396 Jun 20 05:07 linuxhint.html
FTP Protocol:
Both cURL and wget support downloads on FTP protocols. However, cURL supports uploading to ftp.
Use the command below to download files from FTP server with wget:
wget --user=debian --password='debian' ftp://192.168.0.112/backup.zst
--2021-06-20 05:29:06-- ftp://192.168.0.112/backup.zst
=> ‘backup.zst’
Connecting to 192.168.0.112:21... connected.
Logging in as debian ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD not needed.
==> SIZE backup.zst ... done.
==> PASV ... done. ==> RETR backup.zst ... done.
backup.zst
[ <=> ] 0 --.-KB/s in 0s
2021-06-20 05:29:06 (0.00 B/s) - ‘backup.zst’ saved [0]
Using curl, add the -u flag as:
curl -u debian:debian ‘ftp://192.168.0.112/backup.zst’ -o backup.zst
curl -u debian:debian 'ftp://192.168.0.112/backup.zst' -o backup.zst
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
To upload a file to ftp with curl, we use the -T option as:
curl -u debian:debian -T “backup1.zst” ftp://192.168.0.112/ftp/
Ensure the directory exists and the user has write permissions to it.
NOTE: Although cURL supports a wide variety of protocols, it does not provide recursive downloads. On the other hand, Wget supports recursive downloads using the –recursive option as both HTTP/HTTPS and FTP/FTPS protocols offer, such functionality.
Similarities Between wget and cURL
Now for the icing on the cake:
- Both tools support standard protocols such as HTTP, HTTPS, FTP, FTPS.
- Both tools download files from the internet.
- Both tools support HTTP cookies.
- Both tools support output to a file.
- Both free and actively developed tools.
- Both tools support resume transfers.
- Both tools support HTTP POST.
Differences Between wget and cURL
Here are some of the differences between curl and wget:
- Wget is a simple transfer utility, while curl offers so much more.
- Curl provides the libcurl library, which can be expanded into GUI applications. Wget, on the other hand, is a simple command-line utility.
- Wget supports fewer protocols compared to cURL.
- Recursive downloads are not supported in curl.
- Wget is natively available in Linux systems, while cURL is readily available in Windows systems.
- cURL supports multiple parallel transfers.
- cURL performs Transfer-Encoded HTTP decompressions, while wget does not.
- cURL supports bidirectional HTTP while wget offers a plain HTTP POST.
- cURL supports more HTTP auth methods compared to wget.
- Wget does not support SOCKS.
- Wget requires gnulib installed.
- Unlike curl, features such as cookies, timestamps, and follow redirects are enabled by default in wget. cURL requires each to be specified explicitly.
Conclusion
This tutorial focused on the similarities and the differences between cURL. Although it may seem like cURL is the superior choice, there are instances where wget is the best choice.
My advice to you is to choose what works for you.