Hello everyone, I am Internet old xin, this is my 17th day to participate in the more wen Challenge, the activity details: more Wen Challenge

Overview of the FTP service

1. Concepts related to FTP

FTP is short for File Transfer Protocol. It works at layer 7 of the OSI model and layer 4 of the TCP model, that is, transport. TCP is used for transport instead of UDP. In this way, the FTP client has to go through a process known as “three-way handshake” before establishing a connection with the server. The significance of this process lies in that the connection between the client and the server is reliable and connection-oriented, providing a reliable guarantee for data transmission.

The FTP service uses the File Transfer Protocol (FTP) to upload and download files. It facilitates long-distance file transfer and supports the resumable breakpoint transfer function, which greatly reduces the CPU and network bandwidth costs and implements security control.

2. Common FTP servers

Common FTP servers: Windows: Serv -u, FTP Server, and Filezilla_server Linux: ProFTPD :(Professional FTP daemon) an FTP server program running on Unix or unix-like platforms such as Linux, FreeBSD, etc.

We will focus on VSFTP here

3. Basic VSFTP information

VSFTP is an FTP server software distributed based on the GPL and used on unix-like systems. Its full name is Very Secure FTP, which can be seen from the name, the original intention of the compiler is code security. Features: It is a secure, high-speed, stable FTP server.

VSFTP mode: C/S mode Listening port: 20 and 21 service ports, which can be viewed in the /etc/services file

vim /etc/services

FTP monitors two ports: port 20: used for data transmission port 21: used for command transmission

Two working modes and principles of FTP

1) Two working modes of FTP are introduced

There are two FTP connection modes: command connection and data connection. There are two FTP data connection modes: active and passive.

The FTP session connection consists of two channels. One is called the control channel and the port number is 21. One is called data Channel, port number 20.

Control channel: The control channel is used to communicate with the FTP server, connect to the FTP server, and send FTP commands.

Data channel: The data channel is used to transfer files or list files to the FTP server.

In FTP, the control connection is initiated by the client, and the data connection works in PORT mode and PASV mode

1.FTP PORT (active mode) and PASV (passive mode)

(1) PORT (Active mode)

PORT is called active mode in Chinese. How it works:

The FTP client connects to PORT 21 of the FTP server → sends the user name and password to log in. After the login is successful, the client needs to list or read data → opens a random PORT (above 1024) → sends the PORT command to the FTP server. Tell the server that the client is in active mode and open the PORT → After receiving the PORT active mode command and the PORT number, the FTP server connects to the PORT opened by the client through PORT 20 of the server and sends data. The principle is as follows:

2) PASV (Passive mode)

PASV is the abbreviation for Passive mode. It works as follows:

The FTP client connects to port 21 of the FTP server → sends the user name and password to log in and then lists or reads data → sends the PASV command to the FTP server → The server randomly opens a local port (above 1024) → tells the client about the open port. The client then connects to the open port of the server for data transmission. The principle is shown as follows:

Iv. FTP installation

1) Server installation:
[root@gaosh-17 ~]# yum install vsftpd
Copy the code
2) Client installation:
[root@gaosh-17 ~]# yum install lftp
Copy the code

Note: Starting from CentOS, the system image does not have FTP client commands by default. Instead, the LFTP command is used.

Linux client: LFTP is a powerful download tool that supports protocols for accessing files: FTP, FTPS, HTTP, HTTPS, HFTP, and fish(FTPS and HTTPS must contain the OpenSSL library during compilation). The interface of LLFTP is very similar to a Shell, with command completion, history, and multiple background tasks, which is very convenient to use. It also has bookmarking, queuing, mirroring, breakpoint continuation, multi-process download, and other functions.

Configuration file structure

VSFTPD core files and directories:

  • /etc/pam.d/ VSFTPD # VSFTPD configuration file based on PAM authentication
  • /etc/logrotate.d/ VSFTPD
  • /etc/rc.d/init.d/ VSFTPD # VSFTPD startup script for the server to call
  • /etc/vsftpd # VSFTPD home directory
  • /etc/vsftp/ftpusers
  • /etc/vsftp/user_list # specifies the user list file that is allowed to use VSFTPD
  • /etc/vsftp/vsftpd. conf
  • /var/ftp # VSFTPD default shared directory (root directory for anonymous users)
  • /etc/vsftp/vsftpd_conf_migrate. Sh # /etc/vsftp/vsftpd_conf_migrate

The service start

Start the service and set the boot

[root@gaosh-17 ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[root@gaosh-17 ~]# 
Copy the code

Viewing Listening Ports

[root@gaosh-17 ~]# netstat -antup |grep ftp
tcp6       0      0 :::21                   :::*                    LISTEN      3607/vsftpd         
[root@gaosh-17 ~]# 
Copy the code

Note: Here we can only see one port, and port 20 is only open when there is data transfer.

FTP is the usage method

1. Use a browser to access or open a folder, and enter ftp://192.168.1.17/ in the address box.

As shown in figure:

2. Use LFTP
[root@gaosh-17 ~]# lftp 192.168.1.17LFTP 192.168.1.17:~> ls drwxr-xr-x 2 0 0 6 Apr 01 04:55 pub LFTP 192.168.1.17:/>Copy the code

conclusion

This article mainly discusses the principle and use of FTP, not the configuration file. In the next article, we will discuss the detailed parameters of the configuration file.