Different Types of File Transfer Protocol (FTP) for Linux Servers
This tutorial is to familiarize the commonly used file transfer methods for Linux hosts.
Here are the most commonly used File transfer utilities.
FTP is file transfer protocol and is focused on data distribution or file sharing between two host machines in a network of computers.
How to establish FTP connection via Command Line
FTP can be accessed from a Linux machine using the ‘ftp’ command.
Open a terminal and type the command,
Replace Hostname/IP Adress in the above command with the actual Hostname or Domain name or IP address of the FTP server to which you are connecting. (eg: ftp fletcher.pickaweb.co.uk or ftp 188.8.131.52). This command will prompt the ftp username and password. Enter the username and password and that will establish the FTP connection between the FTP server and your local host.
Here is a screenshot you can refer.
FTP username used in the above screenshot is ‘firstname.lastname@example.org‘, you’ll have to replace this with the actual FTP username and it’s password.
You can transfer the files with the FTP commands like get, put etc. To view the FTP commands type help in the FTP prompt.
FTPS is FTP over SSL. This will help in transferring encrypted data over FTP file sharing.
How to establish FTPS connection via Command Line
FTPS can be established with ‘ftp-ssl’ command if the FTP service (eg:- vsftpd, pure-ftpd, pro-ftpd etc) is secured with SSL. Syntax is same as that of the FTP. ‘ftp-ssl’ is a separate package and needs to be installed if not done.
Ofcourse, make sure you replace the Hostname or Domain_name or IP Address field with the original Hostname/IP Address of the server or the Domain name which resolves to the FTP server.
Take a look at the screenshot below.
In the screenshot you can see a highlighted line. It shows the SSL encryption method used in the file transfer. With this you can be sure that the FTP connection is secured with SSL/TLS.
You can make use of the FTP commands (eg: put, get, mkdir, rmdir etc) for the file transfer.
SCP is secure copy. It is a commonly used file transfer method which is based on SSH tunnelling. SSH server should be installed in the destination host (host to which the files are to be transferred) and SSH client should be installed in the local host (client from which data files are to be transferred) for establishing transfer activity.
How to transfer file with SCP via Command Line
Just open up a terminal and enter the scp command in the following syntax,
Syntax: scp -P port "filename" user@HOSTNAME/IPADRESS:/data/directory
Replace port with the SSH port (in case custom SSH port is enabled), user with the SSH user you are connecting to as, HOSTNAME/IPADRESS with the actual hostname or IP address of the destination host or server. and /data/directory with the full path location where the data is to be stored.
Here is a screenshot of scp file transfer that you can look into.
The issue with SCP file transfer is that it is non-interactive, i.e, once you execute the command, it eithers completes the file transfer or errors out if you don’t have sufficient permissions.
SFTP is SSH File Transfer Protocol. It is a separate File Transfer protocol which uses SSH tunneling. This utility establishes a secure and interactive connection between the local and remote hosts and hence it is one of the most preferred and recommended utilities used for file transfer and data sharing. If you are able to access the remote host via SSH, you should be able to access remote host via SFTP.
How to transfer file with SFTP connection via Command Line
Open a terminal and enter the syntax given below.
Syntax: sftp -P port username@hostname_or_IPAddress_of_remote_host
This will establish an interactive SFTP connection between the local and remote hosts. You can transfer the files with the SFTP commands. You can use the command help in the SFTP prompt to view the SFTP commands.
In the above screenshot you can see the SFTP commands and a test file is uploaded with put command. You can exit out of the SFTP prompt with exit command.
RSYNC stands for Remote sync. It synchronizes the files and folders in the local and remote hosts, i.e if for eg: local host contains a directory testdir with test files 1 to 10 and the remote host contains directory testdir with test files 1 to 5, then with Rsync utility you can sync or copy the test files 6 to 10 in the remote host. And if the directory testdir is not present in the remote host, it will be created along with the test files in it.
How to Sync files in local and Remote hosts with Rsync
Open a new terminal and execute the ‘rsync‘ command in the given syntax.
Syntax: rsync options source destination
To Sync/Copy a file
rsync -avzh filename usename@hostname_or_IPAddress_of_remote_host:/data/directory
To Sync/Copy a directory,
rsync -avzh /data/directory usename@hostname_or_IPAddress_of_remote_host:/data/directory
Rsync is one of the most effective File transfer and Data migration tool as it can Sync data in the real time and is best preferred by system admins around the globe. It can be used to create live backups in production server environments.
There you have it. Some of the most popular File Transfer options for Linux Hosting.