What Will We See Here?
In this article, we will explore how to use the ftp command for remote system connection, file transfer, and managing the remote and local files and directories.
What Will We Need?
- Access to a remote FTP server from the local system. To keep it simple, we use a VirtualBox environment.
- FTP components are installed on both the local and remote systems.
NOTE: Since the FTP traffic is unencrypted, it is therefore an unsecured service. We thus recommend not to use it to transfer sensitive data over the internet and other unreliable networks.
FTP Command Syntax
The FTP command has the following syntax:
Here, [IP] denotes the IP address of the target remote system.
The FTP command uses the FTP protocol to connect a system to another system, which is usually a remote server, using the FTP protocol.
After a connection is established, users can also transfer files between the connected systems and manage the files and directories on them.
Creating an FTP Connection
We can create an FTP connection to a remote server using it’s IP address along with the FTP command:
For example, to connect to a remote server with the 192.168.56.10 IP address, run the following command:
When prompted, enter the credentials for the FTP user. Let’s see a live example of logging into an FTP server.
FTP Logging a Server
As soon as we establish a connection to the FTP server, we need to enter the username and the password to log in:
After entering the right credentials, we should be on the FTP interface:
Alternatively, we can first run the FTP command. Then, use the following command on the FTP interface:
From this interface, we can interact with the local machine as well as the remote server. We will soon see this in the following sections.
Listing the FTP Commands
Once we are inside the FTP interface, we can see and use all its commands. Let’s see all the supported commands by simply entering the “?”:
This represents us with many commands like dir, ls, disconnect, and so on. Let’s take a hand on a bunch of them.
Listing the Directory Contents
Let’s first see how we can list the content of the current directory on the remote system like the FTP server. Simply use the dir command here:
As mentioned earlier, we can manage the local machine from the remote machine. Let’s see how we can display the contents of the local directory:
The previous command displays the contents of our local system. To get more detailed listing, we can run the following command:
Similar to pwd which displays the current directory path, we can use the lcd command to display the same local path from the remote machine:
Changing the Current Directory
To navigate to the other directories on the remote server, we can use the usual cd command. For example, from the remote directories that are listed previously, we can change to the directory upload:
Uploading the Files
We can use the put command to send a single file to a remote server. Let’s see how to do this by simply uploading a from_local.txt local file:
After the command is successful, we will see a message like “Transfer complete”. By default, the file lands in the current directory on the remote server. However, we can customize this location by specifying the full path:
We can also use the dot (.) separator to denote the current path:
Let’s now see how to deal with multiple file uploads. We can use the FTP mput command to upload multiple files. For this, we need to specify the file names separated by spaces:
Interestingly, we can use the wildcards here if the file names share something in common. For example, to upload all the files with the name file but with different types, we can use the following command:
Before you can upload the files, you have to enter “yes” to confirm your action.
Downloading the Files
Let’s see how to download the files from the remote server to the local system. Instead of using put, we need to use its antonym like get. For instance, we can download/send a file, say file3.txt, to the local system as follows:
As seen in the uploaded scenario, we can also download a file to the directories other than the current directory on the local system. Just specify the full path on the local system:
Similar to mput, we can use the mget command to download multiple files. Again, let’s see it in action:
Also, the wildcards can simplify our work for similar types of files:
Conclusion
In this article, we cover a high-level overview of the FTP command on Linux. Besides the FTP client, there are other FTP clients for Linux such as Lftp, FileZilla, etc.