Learn how to download any file using command line from internet or FTP servers to your Linux server. Get files in your server in seconds!
There are many times when you want a file on your Linux server from Internet or FTP server and you are on command line terminal! When using GUI of Linux, its easy to get file by using browsers but for command line its little bit difficult.
We have 4 tools here to help you with the task! They are :
Most popular utility! wget is a package you can install and use it right out of the box. You can install it with YUM or APT package. Once install you can use it with supplying URL of the targeted download.
# wget https://kerneltalks.com/image.png
--2017-03-05 06:56:54-- http://kerneltalks.com/image.png
Resolving kerneltalks.com... 188.8.131.52
Connecting to kerneltalks.com|184.108.40.206|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12477 (12K) [image/png]
Saving to: “image.png”
100%[===================================================================================================================>] 12,477 --.-K/s in 0s
2017-03-05 06:56:55 (782 MB/s) - “image.png” saved [12477/12477]
In above example we have downloaded one picture file from internet! File will be saved in your present working directory by default.
# wget ftp://rpmfind.net/linux/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/s/systemd-233-2.fc27.x86_64.rpm
--2017-03-05 06:58:54-- ftp://rpmfind.net/linux/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/s/systemd-233-2.fc27.x86_64.rpm
Resolving rpmfind.net... 220.127.116.11
Connecting to rpmfind.net|18.104.22.168|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /linux/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/s ... done.
==> SIZE systemd-233-2.fc27.x86_64.rpm ... 3179496
==> PASV ... done. ==> RETR systemd-233-2.fc27.x86_64.rpm ... done.
Length: 3179496 (3.0M) (unauthoritative)
100%[===================================================================================================================>] 3,179,496 1.85M/s in 1.6s
2017-03-05 06:58:57 (1.85 MB/s) - “systemd-233-2.fc27.x86_64.rpm.1” saved 
In this example we used wget to download file from FTP server. It used anaonymous login to get into server and download file!
There are several options which you can used according to your requirement. Listing below few important ones.
- -b : send copy progress in background
- -c : continue download (breaked or paused donwload resume)
- -r : recursive (download all files in destination)
- -A fileextension : download only files with specified extension
Curl is simple downloader which supports many protocols for file transfer few being ftp, https, https, telnet etc. It can be installed using same above method yum install curl or apt-get install curl.
Curl renders file downloaded to its best known way. Like if you try to download html URl then it will render it and shows you html code on terminal :
# curl https://kerneltalks.com
<!DOCTYPE html><html lang="en-US" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#"><head ><meta charset="UTF-8" /><title>Kernel Talks - Unix, Linux & scripts.</title><meta name="viewport" content="width=device-width, initial-scale=1" /><meta name="google-site-verification" content="jeFc7PXM8ZxDY5awb8nCCD5-bYwj5S7bwsAIgp1JIgU" /><meta name="msvalidate.01" content="920806CD9A79B08EC8477C0D440658A4" /><meta name="p:domain_verify" content="738d0b16e329ab01cc894a68d2adda34" /><meta name="yandex-verification" content="bd079834c4df4ebf" />
See above example where it shows html code of URL. Same way if you get text file it will show you text file content on terminal.
To only download file without trying to read/open it on terminal use option -o with curl.
# curl -O ftp://rpmfind.net/linux/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/s/systemd-233-2.fc27.x86_64.rpm
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3104k 100 3104k 0 0 361k 0 0:00:08 0:00:08 --:--:-- 618k
It will download file and progress will be shown on terminal in real time.
elinks is text beased browser which supports colors, rendering, tabbed menus etc. Mostly its preloaded with Installations but if not you can install it using yum or apt-get. Let try to download website using elinks http://kerneltlaks.com :
Above example shows elinks renders website in text mode (kind of) on terminal!
If you try to download image (or any type of) file it will show you below GUI screen (within terminal) with options to choose from what to do next. If you choose save then it will download file and keep it.
Last tool of this article to download internet based files is w3m. w3m is text based www (world wide web) client. Installation steps remain same yum/apt-get install w3m
It also opens up text mode GUI screen like elinks and gives you interactive options to choose actions. w3m ftp://rpmf…../…86_64.rpm opens :
If you right click on terminal window (normally we dont!!) it does show you menu you can use to perform various actions.
You can navigate through this menu using keyboard arrow keys or even using mouse clicks. You can even use short cut keys defined for each menu item in brackets beside them.
All user interactive commands/options are shown in lower left corner of the terminal and choices can be submitted there only.
In all if you are looking for a simple tool, less eye rolling on screen, fast way to get file on server then wget is the choice you should make IMHO! Let me know which command line tool you use for downloading internet files in comments.