web123456

Linux ftp command tutorial: How to use ftp command for file transfer (with detailed example explanation and precautions)

Introduction to Linux FTP commands

FTP (File Transfer Protocol) is a standard network protocol used to transfer files on a remote network. In most cases, you will use a desktop FTP client to connect to a remote server and download or upload files. However, the ftp command is very useful when you work on a server without a GUI and want to transfer files over FTP to or from a remote server.

Linux versions that apply to Linux FTP commands

FTP commands are available in all mainstream Linux distributions. If it is not available in some Linux distributions, you may need to install the FTP client. In CentOS 7 and CentOS 8, the command to install an FTP client may vary. In CentOS 7, you can useyumcommands to install, and in CentOS 8 you may need to usednfCommand to install.

[linux@ ~]$ sudo yum install ftp

or

[linux@ ~]$ sudo dnf install ftp

For Debian-based systems

[linux@ ~]$ sudo apt-get install ftp

Basic syntax of Linux FTP commands

The basic syntax of FTP command is as follows:

ftp [options] [host]

Here,optionsis an option for the FTP command.hostIt is the IP address or domain name of the remote FTP server you want to connect to.

Common options or parameter descriptions for Linux FTP commands

Some common options for FTP commands include:

  • -v: Display all response information.
  • -d: Enable debug mode.
  • -i: Close the interactive prompt.
  • -n: Suppress automatic login.

Example of Linux FTP command

Here are some examples of FTP commands:

Example 1: Establish an FTP connection

To open an ftp connection to a remote system, call the ftp command followed by the remote server IP address or domain name. For example, to connect to an FTP server located at "192.168.42.77", you can type:

[linux@ ~]$ ftp 192.168.42.77

If the connection is established, a confirmation message will be displayed and you are prompted for the FTP username².

Example 2: List files and directories in remote directories

To list the names of files and directories in the current remote directory, you can uselsOrder:

[linux@ ~]$ ls

Example 3: Download remote files

To download files from a remote server, you can usegetOrder. For example, to download a file named "", you can type:

[linux@ ~]$ get 

This will download the "" file on the remote server to the local current directory.

Example 4: Upload local files

To upload local files to a remote server, you can useputOrder. For example, to upload a file named "", you can type:

[linux@ ~]$ put 

This will upload the "" file in the local current directory to the remote server.

Example 5: Delete remote files

To delete files on the remote server, you can usedeleteOrder. For example, to delete a file named "", you can type:

[linux@ ~]$ delete 

This will delete the "" file on the remote server.

Example 6: Exit the FTP session

To exit an FTP session, you can usebyeOrder:

[linux@ ~]$ bye

This will end the FTP session and return to the local shell.

Example 7: Change the remote directory

To change the current directory on the remote server, you can usecdOrder. For example, to change to a directory named "example", you can type:

[linux@ ~]$ cd example

This will change the current directory on the remote server to "example".

Example 8: Create a remote directory

To create a new directory on a remote server, you can usemkdirOrder. For example, to create a directory named "example", you can type:

[linux@ ~]$ mkdir example

This will create a new directory on the remote server called "example".

Example 9: Delete Remote Directory

To delete a directory on a remote server, you can usermdirOrder. For example, to delete a directory named "example", you can type:

[linux@ ~]$ rmdir example

This will delete the "example" directory on the remote server.

Example 10: Rename the remote file

To rename a file on a remote server, you can userenameOrder. For example, to rename a file named "" to "", you can type:

[linux@ ~]$ rename  

This will rename the "" file on the remote server to "".

Example 11: View the contents of remote files

To view the contents of files on the remote server, you can usegetThe command downloads the file locally and then usescatCommand to view file content. For example, to view the contents of a file named "", you can type:

[linux@ ~]$ get 
[linux@ ~]$ cat 

This will download the "" file on the remote server to the local current directory and then display the contents of the file.

Example 12: Change the local directory

To change the local current directory, you can uselcdOrder. For example, to change to a directory named "example", you can type:

[linux@ ~]$ lcd example

This will change the local current directory to "example".

Example 13: View the local directory

To view the local current directory, you can uselpwdOrder:

[linux@ ~]$ lpwd

This will display the local current directory.

Example 14: Set FTP mode

There are two modes for FTP: active mode and passive mode. By default, FTP clients use active mode. In some cases, you may need to switch to passive mode due to a firewall or network configuration. To set FTP to passive mode, you can usepassiveOrder:

[linux@ ~]$ passive

This will set FTP to passive mode.

Notes on Linux FTP commands

  • FTP traffic is not encrypted. For secure data transfer, use SCP or SFTP.
  • When transferring large files, it is recommended to run the ftp command on the screen or in the tmux session.
  • If you receivebash: ftp: command not foundThe error message may be because the FTP client is not installed on your system. You can install it as described above.

Linux FTP related commands

  • sftp command: SSH to remote server and securely transfer files between local and remote systems
  • scp command: Used to securely copy files between local and remote systems
  • tar command: used to archive files
  • cat command: used to view file content
  • chmod command: used to change file permissions
  • grep command: used to search for specific text patterns in files
  • cd command: used to change the current directory
  • ls command: used to list files in a directory

For more details, please refer to:
Linux ftp command tutorial: How to use the command line interface for FTP file transfer