How to use Linux FTP command to transfer files
FTP stands for File Transfer Protocol. Is an application layer protocol used to transfer files between clients and servers on a computer network
FTP stands for File Transfer Protocol. Is an application layer protocol used to transfer files between clients and servers on a computer network
In most cases, you will use a desktop FTP client to connect to a remote FTP server to download or upload files.
However, the FTP command is useful when you are working on a server without a GUI and want to upload files to a remote server via ftp or transfer and download files from a remote server.
When data is transferred through ftp, the connection is not encrypted. To transfer data securely, use SCP. To be able to transfer files.
You must have at least read permission to the source file and write permission to the target file system.
When transferring large files, it is recommended to run ftp commands in nohup, screen, or tmux sessions.
These commands enable FTP to run in the background. The directory where the ftp command is run is the local working directory.
To open an ftp connection to a remote system, run the ftp command, followed by the remote server IP address or domain name.
If the connection is established, a confirmation message is displayed and you are prompted for an FTP user name, which in this case is myfreax
.
Depending on the configuration of the FTP service running on the remote server, you may see different confirmation messages. After entering the user name, you will be prompted for a password.
If the password is correct, the remote server displays a confirmation message and an ftp>
prompt.
If the FTP server you are accessing accepts anonymous ftp accounts and you want to log in as an anonymous
user, use anonymous as the user name.
ftp 192.168.42.77
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 50 allowed.
220-Local time is now 21:35. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
Name (192.168.42.77:localuser): myfreax
Password:
230 OK. Current restricted directory is /
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
Common FTP commands
Many FTP commands are similar or identical to those you type at the Linux Shell prompt. Here are some of the most common FTP commands.
Help
or?
- Lists all available FTP commands. cd
Changes the directory on the remote computer. lcd Switches directories on the local computer.
ls
Lists the names of files and directories in the current remote directory. mkdir
Creates a new directory in the current remote directory.
pwd
Prints the current working directory on the remote computer.
delete
Deletes files in the current remote directory. rmdir
Deletes a directory in the current remote directory.
get
copies a file from a remote to a local computer. mget
copies multiple files from a remote location to a local computer.
put
Copies a file from the local computer to a remote machine. mput
copies a file from the local to a remote machine.
Downloading Files through FTP
After logging in, your current working directory is the FTP working directory.
When you use the ftp command to download a file, the file will be downloaded to the directory where you typed the ftp command.
To download the file to another local directory, run the lcd command to switch to this directory. Suppose we want to download a file to the ~/ftp_downloads
directory.
Run the lcd ~/ftp_downloads
command to switch to the ~/ftp_downloads
directory.
lcd ~/ftp_downloads
To download a single file from a remote server, use the get
command. To download multiple files at once, use the mget
command.
You can provide a list of individual file names or use wildcards to match the file names to download.
When you download multiple files, you will be prompted to confirm each file. After downloading files from the remote FTP server, use bye
or quit
to close the connection.
For example, to download a file named backup.zip, run the command get backup.zip
.
get backup.zip
mget backup1.zip backup2.zip
quit
mget backup1.zip? y
200 PORT command successful
150 Connecting to port 52231
226-File successfully transferred
226 0.000 seconds (measured here), 31.51 Kbytes per second
14 bytes received in 0.00058 seconds (23.6 kbytes/s)
mget backup2.zip? y
200 PORT command successful
150-Connecting to port 59179
150 7.2 kbytes to download
226-File successfully transferred
226 0.000 seconds (measured here), 16.68 Mbytes per second
7415 bytes received in 0.011 seconds (661 kbytes/s)
Uploading Files through FTP
To upload a local computer file to a remote FTP server, use the put
command.
If you want to upload a file that is not in the current working directory, use the absolute path of the file. To upload multiple files locally to the FTP server, use the mput
command.
When you upload multiple files, you will be prompted to confirm each file you want to upload.
After uploading the file to the remote FTP server, use bye
or quit
to close the connection.
put image.jpg
mput image1.jpg image2.jpg
mput image1.jpg? y
200 PORT command successful
150 Connecting to port 41075
226-File successfully transferred
226 1.439 seconds (measured here), 102.89 Kbytes per second
151586 bytes sent in 1.07 seconds (138 kbytes/s)
mput image2.jpg? y
200 PORT command successful
150 Connecting to port 40759
226-File successfully transferred
226 1.727 seconds (measured here), 111.75 Kbytes per second
197565 bytes sent in 1.39 seconds (138 kbytes/s)
conclusion
In this tutorial, you learned how to download and upload files to a remote ftp server using the FTP command.