FTP or File Transfer Protocol is a network protocol that is used to transfer files to & from a remote location. If you are looking to set up an FTP server, then please go through the tutorials mentioned HERE & HERE.
In this tutorial, we are going to discuss how to use Linux FTP or SFTP command to manage files and directories FTP server using the command line interface. Though there are many GUI clients available that can be used to manage files but there are many a time when CLI is the best option.
So let’s start our tutorial on how to use the Linux FTP command in the command line interface.
NOTE:- FTP command can be interchanged with the SFTP command. All the commands mentioned below in examples will use FTP but the same can be used for sftp as well. Just replace FTP with sftp & you are good to go. The only difference that FTP and SFTP have is that FTP is unsecure & unencrypted but SFTP is encrypted.
Recommend Read: Linux commands you should never run on your system
Also Read: How to use SCP & RSYNC command line options to Backup your System
Linux FTP command examples for command Line interface
Connect to FTP server
To connect to FTP server, execute the following command,
# ftp test.ftp.com
OR
# test 10.10.10.10
OR
# test admin@10.10.10.10
We can use either a domain name or IP address or a user name with IP address/domain.
If you are using anonymous login then, you will not be asked to enter credentials & will directly be connected to the FTP server but if you have authentication enabled, you will first be asked to enter a username (if not provided during connecting command) & once the username has been entered, you will be asked to enter the password associated with the mentioned user.
After connecting to ftp, the bash prompt will change too,
ftp>
Disconnecting from a server
In order to disconnect from the FTP server, we can use either of the three commands,
ftp> bye
OR
ftp> exit
OR
ftp> quit
Commands to use once connected to FTP
Once we are connected to ftp server, there are many commands that we can use to manage files & directories in ftp server, similar to how we manage files & directories in a local Linux server. Some of the most commonly used commands used when connected to ftp server are,
cd - change directory on the ftp server
lcd - change directory on the local server
ls - list the files and directories in the ftp server
pwd - Print the current working directory on the ftp server
mkdir - create a new directory in ftp server
rmdir- remove a directory in the ftp server
delete - remove a file in the ftp server
get - copy one file from ftp to the local server
mget - copy multiple files from the ftp server to the local server
put - copy one file from the local server to the ftp server
mput - copy one file from the local server to the ftp server
help or ? - list all available FTP command
Downloading a file from FTP server
Once you are at the location where the file is located that you need to download, then run the following command after connecting to the FTP server,
ftp> get file_needed_to_download.zip
If there are multiple files that are required to be downloaded, then use ‘mget’,
ftp> mget file_1.zip file_2.zip
Uploading a file to FTP server
To upload files from local directory to ftp server, once the connection has been made, use the following command,
ftp> put file_needed_to_upload.zip
If you need to put multiple files on ftp, use the ‘mput’ command,
ftp> mput file_1.zip file_2.zip
That’s it, this completes our tutorial on how to use Linux FTP (SFTP) in the command line interface or CLI. If you have any questions or queries regarding this tutorial, please do send you questions or queries in the comment box below.
We are giving you exclusive deals to try Linux Servers for free with 100$ credit, check these links to claim your 100$,
DigitalOcean - 100$ free credit & Linode - 100$ free credit
Check some Exclusive Deals, HERE.
Also, check out DevOps Book You should read section.