The file transfer protocol is older than most of our readers, but it is still strong. FTP does not provide security for a modern protocol, but you may need to use it anyway. Here's how.
Warning: Do not use FTP over the Internet
Let's make it clear from the beginning: The FTP file (File Transfer Protocol) goes back to the early 1
If you are transferring files to your network, you should be safe as long as no one in the network packs and snaps on sensitive documents when you upload them. If your files are not confidential or sensitive in any way, it should be good to move them around your internal network with FTP. Linux has the standard
ftp command line program to handle exactly that scenario.
But definitely does not use the command
ftp to access external resources over the internet. For that, use the
sftp command line program, which uses the secure SSH File Transfer Protocol. We introduce both of these programs in this guide.
To clarify just why you never want to use FTP via the Internet, take a look at the screenshot below. It displays the FTP password in plaintext. Someone on your network or between you and the FTP server on the Internet can easily see the password is "MySecretPassword."
Without encryption, a malicious actor can change files you download or upload during transit. 
If you assume you have a valid account on an FTP site, you can connect to it with the following command. In this article, replace the IP address in the commands with the IP address of the FTP server you connect to.
Warning : You should only use the
ftp command to connect to servers on a trusted local area network. Use the
sftp command below to transfer files over the Internet.
The FTP server responds with a welcome message. The wording of the greeting varies from server to server. It then asks the user name for the account you are logging in to.
Please note that the IP address of the site you are connecting to is displayed, followed by your Linux username. If your account server name on the FTP server is the same as your Linux username, simply press the Enter key. This will use your Linux username as the account name on the FTP server. If your Linux username and FTP account name is different, enter your FTP account username and then press Enter.
Log in to the FTP server
You will be prompted to enter your password for the FTP site. Enter your password and press Enter. Your password does not appear on the screen. If your FTP user account name and password combination are verified by the FTP server, then log in to the FTP server.
You will be presented with the
Searching and retrieving files
First you will probably get a list of the files on the FTP server. The command
ls does just that. Our user sees the file
gc.c available on the FTP server, and he wants to download it to his own computer. His computer is the "local computer" in the FTP language.
The command to download (or "get") a file is
get . Our user therefore issues the command
get gc.c . They write
to get a space and then the name of the file they want to download.
The FTP server responds by transferring the file to the local computer and confirming the transfer took place. The file size and the time it took to transfer are also displayed.
To retrieve multiple files simultaneously, use the command
mget (multiple get). The command
mget will ask you to confirm if you want to download each file in turn. Respond by pressing "y" for yes and "n" for no.
This would be boring for a large number of files. Because of this, collections of related files are usually stored on ftp sites as single tar.gz or tar.bz2 files.
RELATED: Here's how to extract files from a .tar.gz or .tar. bz2 file on Linux
mget * .c
Transferring files to the FTP server
Depending on the permissions granted to you FTP account allows you to upload (or "put") files to the server. To upload a file, use the
command with . In our example, the user uploads a file called
Songs.tar.gz to the FTP server.
sets the Songs.tar.gz
] As you probably expect, there is a command to put multiple files to the FTP server at the same time. It is called
mput (several sets). Just like the command
mget mput would ask for a "y" or "n" confirmation for uploading each file, one by one.
The same argument for putting files in take archives applies to putting files as it does to get files. Our user uploads several ".odt" files with the following command:
mput * .odt
Create and modify directories
About your ftp user account server allows it, you may be able to create directories. The command to do this is
mkdir . To be obvious, all directories you create with the command
mkdir will be created on the ftp server and not on your local computer.
To change directories on the ftp server, use the CD
cd command, the
ftp> prompt will not change to reflect your new current directory. The
pwd command (write workbook) will show you your current directory.
Our ftp user creates a directory called music, changes to the new directory, confirms where they are using
To quickly move to the parent directory in the current directory, use the command
Accessing the local computer
] To change the directory on the local computer, you can use the
lcd command at
ftp> prompts. However, it is easy to lose track of where you are in the local file system. One more convenient way to access the local file system is to use the command
! opens a shell window on the local computer. You can do something in this shell as you can in a standard terminal window. When writing
exit you are returned to the
Our user has used the command
! and put a shell window on the local computer. They have issued a command
ls to see which files are in that directory and then written
exit to return to the
!  ls  exit ! shell command in a terminal window "width =" 644 "height =" 162 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null ; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "/>
If you want to rename files on the FTP server, use the
rename command. FTP users a file with
renameand then use the
lscommand to list the files in the directory.rename songs.tar.gz rock_songs.tar.gz  ls
To delete files on the FTP server use the command
mdelete.You will be prompted to provide a "y" or "n" confirmation to rate
Here our FTP user has listed the files to see their names and then selected one to delete.delete gc.omdelete * .o
Using the sftp command
] Readers familiar with the IP addressing system have noticed that The 192.168 address of the FTP server used in the above example is an internal IP address, also called a private IP address. As we warned at the beginning of this article, the
ftpcommand should only be used on internal networks.
To connect to a remote or public FTP server, use the
sftp] command. Our user will connect to an SFTP account called
demoon the publicly available FTP server located on
When they connect, they are informed that the connection has been established. They are also informed that the authenticity of the host cannot be verified. This is normally for the first connection a new host. They press "y" to accept the connection.
Since the user account name (
demo) was sent on the command line, they are not prompted for the user account name. They are only prompted for the password.sftp email@example.com
FTP commands we have described above will work the same way in an SFTP session with the following exception.
- To delete a file, use
- To delete multiple files, use
- To move to the parent directory use
cd ..(FTP uses
Our user has used some commands in his SFTP -session. They have use
ls to list the files and
cd to switch to the pub directory. They have used
pwd to print the work directory.
There are other options for transferring files in the Linux world, especially
scp (secure copy), but we have focused on FTP and SFTP here. Used in the current scenarios, these two commands will serve you and your file storage and retrieval will need good.