CIS120Linux Fundementals
wget, ftp and sftp Commands
The wget
, ftp
, and sftp
commands are essential tools for transferring files between computers in Linux. wget
is a non-interactive network downloader, while ftp
and sftp
are used for interactive file transfers, with sftp
being the preferred and more secure option.
The wget Command
The wget
command is used for downloading files from the web. It supports HTTP, HTTPS, and FTP protocols and can download files non-interactively, making it ideal for automated downloads.
Basic usage of wget
:
wget [options] [URL]
Commonly Used wget
Options:
Option | Description |
---|---|
-O |
Write output to a file instead of standard output |
-c |
Resume a partially downloaded file |
-q |
Quiet mode (no output) |
-r |
Recursive download |
-l |
Set the maximum depth for recursive downloads |
--limit-rate |
Limit the download speed |
To download a file using wget
:
wget http://example.com/file.txt
Output:
--2024-07-10 10:00:00-- http://example.com/file.txt
Resolving example.com (example.com)... 93.184.216.34
Connecting to example.com (example.com)|93.184.216.34|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1234 (1.2K) [text/plain]
Saving to: 'file.txt'
file.txt 100%[===================>] 1.21K --.-KB/s in 0s
2024-07-10 10:00:01 (234 MB/s) - ‘file.txt’ saved [1234/1234]
The ftp Command
The ftp
(File Transfer Protocol) command is used to transfer files between a client and a server. It is an older protocol that is less secure compared to sftp
. ftp
transfers data in plaintext, making it vulnerable to interception and attacks. Due to its security limitations, sftp
is now the preferred method for file transfers.
The sftp Command
The sftp
(Secure File Transfer Protocol) command is a secure version of ftp
that uses SSH (Secure Shell) to encrypt the data being transferred. It is preferred over ftp
due to its enhanced security features.
Basic usage of sftp
:
sftp [user@]hostname
Commonly Used sftp
Options:
Option | Description |
---|---|
-b |
Batch mode reads a series of commands from a file |
-C |
Enable compression |
-P |
Specify an alternate port |
-i |
Specify an identity file (private key) |
-q |
Quiet mode |
-v |
Verbose mode |
Examples and Output Explanations
To connect to an SFTP server:
sftp user@ftp.example.com
Output:
Connecting to ftp.example.com...
user@ftp.example.com's password:
sftp>
To list files on the remote server:
ls
Output:
files
file.txt
To list files on the local machine:
lls
Output:
Desktop Documents Downloads file.txt Pictures
To change directories on the remote server:
cd /path/to/remote/directory
Output:
sftp> cd /path/to/remote/directory
To change directories on the local machine:
lcd /path/to/local/directory
Output:
sftp> lcd /path/to/local/directory
To download a file from the remote server:
get file.txt
Output:
Fetching /home/user/file.txt to file.txt
/home/user/file.txt 100% 1234 1.2KB/s 00:00
To upload a file to the remote server:
put localfile.txt remotefile.txt
Output:
Uploading localfile.txt to /home/user/remotefile.txt
localfile.txt 100% 1234 1.2KB/s 00:00
To download multiple files:
mget *.txt
To upload multiple files:
mput *.txt
Differences Between ftp and sftp
The key difference between ftp
and sftp
is security. ftp
transfers data in plaintext, which makes it vulnerable to interception and attacks. In contrast, sftp
uses SSH to encrypt the data being transferred, providing a secure channel that protects the data from being intercepted or tampered with.
Due to its security advantages, sftp
is now preferred over ftp
for file transfers.
Summary
The wget
, ftp
, and sftp
commands are powerful tools for downloading and transferring files in Linux. wget
is used for non-interactive downloads, while ftp
and sftp
are used for interactive file transfers, with sftp
being the preferred option due to its enhanced security features. By mastering these commands and understanding their options, you can efficiently manage file transfers in the Linux environment.