Ftp is very popular file transfer protocol over computer networks and internet. Ftp provides simple but efficient commands and features to download and upload files over network. In this tutorial we will look most used FTP commands.
Ftp是计算机网络和Internet上非常流行的文件传输协议。 Ftp提供了简单而有效的命令和功能,可以通过网络下载和上传文件。 在本教程中,我们将介绍最常用的FTP命令。
If you need to install FTP server look following tutorial.
如果您需要安装FTP服务器,请查看以下教程。
为CentOS,Fedora,RHEL安装Ftp客户端 (Install Ftp Client For CentOS, Fedora, RHEL)
Ftp command is not installed by default most of the distributions. We can install ftp command with the following command.
默认情况下,大多数发行版未安装Ftp命令。 我们可以使用以下命令安装ftp命令。
$ yum install ftp -y
![Install Ftp Client For CentOS, Fedora, RHEL](https://img-blog.csdnimg.cn/img_convert/5202ec080de3a3e86416dbc5631909ae.png)
为Ubuntu,Debian安装Ftp客户端(Install Ftp Client For Ubuntu, Debian)
We can install ftp command for the Ubuntu and Debian like below.
我们可以为Ubuntu和Debian安装ftp命令,如下所示。
$ apt install ftp
连接FTP服务器 (Connection FTP Server)
First step to connect an ftp server is providing the ip address or domain name of the server to the ftp command. In this example we will connect IP address . The user name and password will be asked. We can use anonymous account which user name and password is anonymous
连接ftp服务器的第一步是向ftp命令提供服务器的IP地址或域名。 在此示例中,我们将连接IP地址。 将会询问用户名和密码。 我们可以使用匿名帐户,其用户名和密码是anonymous
$ ftp 192.168.122.156
![Connection FTP Server](https://img-blog.csdnimg.cn/img_convert/338183761d1d965640a2d867b4f0c841.png)
If the authentication is successful we will get 230 Login Successful
response from ftp server.
如果身份验证成功,我们将从ftp服务器获得230 Login Successful
响应。
显示连接状态 (Show Connection Status)
After connecting an ftp server we may need to check the connection status and detailed information about the connection. We can use status
command.
连接ftp服务器后,我们可能需要检查连接状态和有关连接的详细信息。 我们可以使用status
命令。
status
![](https://img-blog.csdnimg.cn/img_convert/15918d9f7133852afa91af80954f295e.png)
列出文件 (List Files)
Remote ftp servers will provide a lot of files and folders. We can list these files and folders with ls
or dir
command like below.
远程ftp服务器将提供许多文件和文件夹。 我们可以使用ls
或dir
命令列出这些文件和文件夹,如下所示。
ls
or
要么
dir
![List Files](https://img-blog.csdnimg.cn/img_convert/f2ff505df9cca5f478d77eea02e6c86d.png)
列出当前工作目录(List Current Working Directory)
We can list current working directory on the remote ftp server with pwd
command.
我们可以使用pwd
命令列出远程ftp服务器上的当前工作目录。
pwd
更改远程当前工作目录 (Change Remote Current Working Directory)
We generally need to change current working directory. We will use cd
command in order to change current working directory on ftp server. In this example we will change to the directory named backups
我们通常需要更改当前工作目录。 我们将使用cd
命令来更改ftp服务器上的当前工作目录。 在此示例中,我们将切换到名为backups
的目录。
cd backups
![Change Current Directory](https://img-blog.csdnimg.cn/img_convert/d854a8313a3e630e9e1c4a34386f9f81.png)
更改本地当前工作目录(Change Local Current Working Directory)
We also have a local current working directory too. This will be used to store downloaded files and looking for upload files. We will use lcd
. In this example we change local current working directory to the /home/ismail/
我们也有一个本地当前工作目录。 这将用于存储下载的文件并查找上传文件。 我们将使用lcd
。 在此示例中,我们将本地当前工作目录更改为/home/ismail/
lcd /home/ismail
从FTP服务器下载或获取文件 (Download or Get File From FTP Server)
Now we can start the show. The most popular command for ftp is get
. get
is used to download files from remote ftp server to the local system. File will be download tot the current local working directory. In this example we will download the backup.tar.gz
现在我们可以开始表演了。 ftp最受欢迎的命令是get
。 get
用于将文件从远程ftp服务器下载到本地系统。 文件将下载到当前本地工作目录。 在此示例中,我们将下载backup.tar.gz
get backup.tar.gz
![Download or Get File From FTP Server](https://img-blog.csdnimg.cn/img_convert/e6911321537bae3c43f4f85bb6ebaf95.png)
从FTP服务器下载或获取多个文件(Download or Get Multiple Files From FTP Server)
Wget use mget
command in order to download multiple files from ftp server.
Wget使用mget
命令以从ftp服务器下载多个文件。
mget backup.tar.gz oldbackup.tar.gz
Also we can use glob *.*
to download all files in the current working directory.
我们也可以使用glob *.*
来下载当前工作目录中的所有文件。
mget *.*
将文件发送或发送到ftp服务器 (Put Or Send File To The Ftp Server)
We will use put
command in order to send or upload local files. In this example we will upload file named backup.tar.gz
. The file must be located in the current local working directory if not change local current working directory accordingly.
我们将使用put
命令来发送或上传本地文件。 在此示例中,我们将上传名为backup.tar.gz
文件。 如果未相应更改本地当前工作目录,则文件必须位于当前本地工作目录中。
put backup.tar.gz
在FTP服务器上创建目录 (Create Directory On Ftp Server)
We can create a directory on the remote ftp server without uploading anything. We will use mkdir
command for this. In this example we will create a directory named public
.
我们可以在远程ftp服务器上创建目录,而无需上传任何内容。 我们将为此使用mkdir
命令。 在此示例中,我们将创建一个名为public
的目录。
mkdir public
删除FTP服务器中的文件 (Delete File In The Ftp Server)
We can use delete
command in order to remove or delete files on the remote ftp server. In this example we will delete the file named backup.tar.gz
.
我们可以使用delete
命令来删除或删除远程ftp服务器上的文件。 在此示例中,我们将删除名为backup.tar.gz
的文件。
delete backup.tar.gz
从FTP服务器删除文件夹或目录 (Delete Folder or Directory From Ftp Server)
We can remove empty directories from ftp server with the rmdir
command. In this example we will remote directory named iso
我们可以使用rmdir
命令从ftp服务器中删除空目录。 在这个例子中,我们将远程目录命名为iso
rmdir iso
![Delete Folder or Directory From Ftp Server](https://img-blog.csdnimg.cn/img_convert/bbdcd3d5320dbaf3852e99e3b4e05b16.png)
从FTP服务器断开连接或退出(Disconnect or Exit From Ftp Server)
We can exit from ftp server interactive shell with the command exit
我们可以使用命令exit
从ftp服务器交互外壳exit
exit
翻译自: https://www.poftut.com/how-to-use-ftp-server-from-command-line-tutorial-with-examples/