Bootstrap FreeKB - Linux Commands - wget (download files from remote systems)
Linux Commands - wget (download files from remote systems)

Updated:   |  Linux Commands articles

On a Linux System, the most popular ways to transfer a file from one Linux system to another Linux system are:

For example, scp or rsync could be used to transfer example.jpg from Machine 1 to Machine 2, or vice versa.

The Secure FTP (SFTP) command can be used to securely transfer files between Mac, Linux and Windows systems.


The wget command can be used to download files from remote systems to your local Linux system. To put this another way, wget can transfer a file from a remote system to your local Linux system. In this example, the wget command is used to download file1.txt from the www.example.com web server.

~]# wget http://www.example.com/file1.txt 

 

In this example, the wget command is used to download file2.txt from the example.com FTP server.

~]# wget ftp://example.com/file2.txt

 


Target Directory

The --directory-prefix option can be used to specify the target directory where the file should be stored.

wget http://example.com/file1.txt --directory-prefix /tmp

 

Or, the -o or --output-document option can be used which allows you to rename the file too if you would like.

wget http://example.com/file1.txt --output-document/tmp/new_file_name.txt

 


Background

Some downloads can take a while. If a download is taking a while, you can switch to another TTY console so that you can continue to interact with the Terminal. Or, you can use the -b or --background option to run wget in the background.

~]# wget -b http://www.example.com/big.iso 

 


Quiet

Wget without any options can produce quite a bit of output. The -q or --quiet option can be used to not display any output when running the wget command.

~]# wget -q ftp://example.com/file3.txt 

 


Username Password

If the target system requires a username and password for the resource being requested, the --user and --password options can be used to provide the username and password.

~]# wget http://www.example.com/file1.txt --user=the_username --password=the_password

 

The --ask-password option can be used to prompt for the password when running the command.

~]# wget http://www.example.com/file1.txt --ask-password

 

Also, the /home/username/.wgetrc file can be created, and the username and password can be stored in the .wgetrc file. If the HTTP and FTP username and password is identical, use this format:

user=your_username
password=your_password

 

If the HTTP and FTP username and password are different, use this format:

ftp_user=your_username
ftp_password=your_password
http_user=your_username
http_password=your_password

 


SSL 

When connecting to a secured system, such as an HTTPS web server or an FTPS server, you may get a prompt like this.

~]# wget https://www.example.com/foo.txt

ERROR: cannot verify www.example.com's certificate, issued by /DC=com/DC=example/CN=example:
  Unable to locally verify the issuer's authority.
To connect to www.example.com insecurely, use `--no-check-certificate'.

 

As the warning suggests, you can use the --no-check-certificate flag if you want to connect.

wget https://www.example.com/foo.txt --no-check-certificate

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter f030b8 in the box below so that we can be sure you are a human.