Linux Series Explanation——Application of FTP Protocol

Briefly introduce the application of FTP file transfer protocol in Linux system.

0. Basic concepts

FTP (File Transfer Protocol): File transfer protocol.

FTP is a protocol for communication and file transfer over a TCP/IP network. FTP can be roughly divided into two parts: FTP Serverand FTP Client. Users can receive and transfer files on FTP servers (also known as FTP hosts/sites). The FTP client connects to the FTP server through the TCP protocol and communicates with it using FTP commands. The FTP client can browse files and directories in the remote FTP server, and download files from the FTP server or upload files to the FTP server.

FTP data transfer can use two modes: active mode and passive mode. In active mode, the FTP server sends data to the FTP client; while in passive mode, the FTP client sends data to the FTP server.

FTP usually uses the standard port 21 for communication. However, the FTP protocol does not support encryption, so additional security measures need to be taken when transferring sensitive information. For example, SFTP (Secure File Transfer Protocol) is an encryption protocol based on the SSH (Secure Shell) protocol, which is used for file transfer on a secure network.

1. FTP Server

1.1 Install FTP Server

sudo apt install vsftpd

1.2 Open and close FTP Server

#启动服务
sudo service vsftpd start

#关闭服务
sudo service vsftpd stop

#重启服务
sudo service vsftpd restart

1.3 Check whether the FTP Server is enabled

sudo service vsftpd status

On state:
insert image description here

Disabled:
insert image description here

1.4 FTP server configuration

The configuration file of vsftpd is /etc/vsftpd.conf, let's talk about the necessary configuration options.

1. Use a local user to log in to the ftp server

parameter illustrate
local_enable=YES Allow local users to log in.
write_enable=YES Allow writing, if not set or set to NO, files cannot be uploaded or deleted.
local_umask=077 The permission mask of the local user, if not set, the default is octal number 077.

Note: Make sure that the user who logs in to ftp or the group to which the user belongs has read and write permissions to the target directory, for example as follows
insert image description here

2. Use an anonymous user to log in to the ftp server

parameter illustrate
anonymous_enable=YES Allow anonymous logins.
anon_root=/home/sun/anondir Anonymous user's root directory, custom path. Must be set, otherwise no directory will be available after anonymous login.
write_enable=YES Allow writing, if not set or set to NO, the settings of anon_other_write_enable and anon_upload_enable will be invalid.
anon_other_write_enable=YES Allow anonymous users to write, if not set or set to NO, the file cannot be deleted. Requires write_enable=YES, otherwise invalid.
anon_upload_enable=YES Allow anonymous users to upload files, need write_enable=YES, otherwise invalid.
anon_mkdir_write_enable=YES Allow anonymous users to create folders, need write_enable=YES, otherwise invalid.
anon_umask=077 The permission mask of anonymous users, if not set, the default value is octal number 077.

There are two points to note about anonymous user login:
(1) Similar to the point of note when a local user logs in to the ftp server, the ftp anonymous user is equivalent to the other user, ensuring that the other user has read and write permissions on the target directory.
(2) On the ftp server, anonymous users 根目录cannot 其他人权限set writable permissions. If writable permissions are set, then ftp anonymous login will report an error.
insert image description here

2. FTP Client

2.1 lftp

lftp has more tab key completion than ftp, and the command line displays the current path. This is recommended.

Install command:

sudo apt install lftp

Basic usage:

lftp ip地址

Example: log in to the 192.168.1.7 host with the administrator
insert image description here

Example: Anonymous login to host 192.168.1.7
requires anonymous login configured on the ftp server. How to configure the ftp server to log in anonymously, the linux system can see the part of FTP Server above.

sun@sun-pc:~$ lftp 192.168.1.7
lftp 192.168.1.7:~>

2.2 ftp

It comes with ubuntu, clear text transmission, no tab completion function, and the command line does not display the current path.
Install command:

sudo apt install ftp

Basic usage:

ftp ip地址

Example: User administrator logs in to host 192.168.1.7
insert image description here

Example: Anonymous login to host 192.168.1.7
requires anonymous login configured on the ftp server. How to configure the ftp server to log in anonymously, the linux system can see the part of FTP Server above.
insert image description here

2.3 sftp

sftp also comes with ubuntu, similar to the ftp client, with an additional ssh encrypted transmission, so I won’t go into details here.

2.4 ftp and sftp integrated in file explorer

Ubuntu's file explorer comes with clients such as ftp and sftp, as follows
insert image description here

3. FTP common commands

The commands of ftp are basically the same as the built-in commands of linux, but there are not many linux commands. After logging in to the ftp server, you can use the following command.

# 上传文件到当前ftp服务器,put的时候可以按tab键会提示本地机器当前目录有哪些文件
put 文件

# 从当前ftp服务器下载文件
get 文件

# 查看有哪些文件,文件夹
lsls -l

# 查看文件内容
cat 文件

# 切换目录
cd 路径

# 创建文件夹
mkdir 文件夹

# 删除文件或目录
rmrm -r

# 退出登录,其中exit只有linux系统的ftp客户端有效
bye 或 quit 或 exit

Guess you like

Origin blog.csdn.net/In_engineer/article/details/130514453