If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.
Using FTP Command to Transfer Files
Last modified: November 26, 2022
1. Overview
In this article, we’ll learn how to use the ftp command in Linux to transfer files between two systems. We can use the ftp command to transfer files from server to client and also from client to server.
FTP doesn’t use encryption. In other words, user credentials (username and password) and file data are sent as plain text. As a result, the connection between the client and the server is vulnerable to different network attacks such as sniffing and spoofing attacks. For more security, we can use SFTP or FTPS since they use encryption.
2. Connecting to the FTP Server
To connect to the FTP server, we can use this command:
$ ftp <ip address or domain name>
For example:
$ ftp localhost
After connecting, it will ask us to enter the username and the password. After that, it gives us the ftp> prompt:
$ ftp localhost
Connected to localhost.
220 (vsFTPd 3.0.3)
Name (localhost:baeldung): <enter username>
331 Please specify the password.
Password: <enter password>
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
We are now successfully connected to the FTP server.
3. Useful Commands
After connecting to the FTP server, we can run these commands:
- get
- mget
- put
- mput
- mkdir
- rmdir
- delete
- mdelete
Now let’s take a quick look at their usage.
3.1. Downloading Files
We can use get and mget to download a file from the FTP server:
ftp> ls
200 EPRT command successful. Consider using EPSV.
150 Here comes the directory listing.
-rw-rw-r-- 1 1000 1000 180103 Apr 24 08:29 file.pdf
226 Directory send OK.
ftp> get file.pdf
local: file.pdf remote: file.pdf
200 EPRT command successful. Consider using EPSV.
150 Opening BINARY mode data connection for file.pdf (180103 bytes).
226 Transfer complete.
180103 bytes received in 0.00 secs (109.0537 MB/s)
We have successfully downloaded file.pdf.
3.2. Uploading Files
We can use put and mput to upload a file to the FTP server:
ftp> put <new file name>
It’ll upload the file from the current local working directory to the server.
3.3. Creating/Removing a Directory
We can use mkdir to create a new directory:
ftp> mkdir <new directory name>
And we can use rmdir to remove a directory:
ftp> rmdir <directory name>
3.4. Deleting a File
We can use delete or mdelete to remove files:
ftp> delete <file name>
4. Exiting the Prompt
After we are done transferring files, we can use exit or bye to exit:
ftp> exit
5. Conclusion
In this short article, we learned how to connect to an FTP server, run several commands, and send files to/from the FTP server.