FTP is one of the protocols in the TCP/IP protocol suite, that is, the file transfer protocol. It works on the fourth layer (application layer) of the TCP model. It uses TCP transmission to use interactive access and allows the client to specify file types and formats. Generally It is ASCII code and text format.
FTP has two ports, one port is used as a control connection port, port 21, which is used to send commands to the server and wait for the server to respond; two ports are data transmission ports, the port number is 20, used to establish data Transmission channel; so there are two FTP connection modes, active and passive, namely PORT and PASV, which are relative to the server, similar to the active and passive of zabbix.
The active mode FTP client establishes a connection channel between its own high port and the TCP port 21 of the FTP server, and sends commands through this channel. When the client needs to receive data, it sends a PORT command on this channel to tell the server that the client uses What port receives the data, so that after the server receives the client's port information, it connects through its 20 port and the client's designated random high port, and the data link is established.
Passive mode is when the client sends a data request, the server will also send a message to the client, telling the client that the server has opened a high port in its local, let the client to connect, when the client receives the server's After the information, it connects to the high random port of the server, and the data link is established.
The two modes are mainly different in data link establishment. The active mode is that the client opens a high port locally and waits for the server to establish a connection, and the passive mode is that the server opens a high port and waits for the client to establish a data connection.
Knowing this is almost the same for understanding FTP. Now let’s introduce how to build active and passive FTP under ubuntu.
1 | sudo apt install vsftpd |
---|
12345 | $ sudo mkdir -p /data/storage$ sudo adduser www$ sudo adduser ftpadmin --ingroup www$ sudo chown -R www.www /data/storage$ sudo chmod g+w /data/storage |
---|
Let me talk about the role of these two users created here: www user is our web user, all applications are controlled by this user; ftpadmin is FTP user
1 2 3 4 5 6 7 8 910111213141516171819202122 | listen=NOlisten_ipv6=YESanonymous_enable=NOlocal_enable=YESdirmessage_enable=YESuse_localtime=YESxferlog_enable=YESconnect_from_port_20=YES #Whether to use port 20 for data transmission in active mode xferlog_file=/var/log/vsftpd/emptam_dir_std_runformat=YES vsftpdrsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pemrsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.keyssl_enable=NOchroot_local_user=YESallow_writeable_chroot=0YESfilewrite_enable=/umask=0666local #Active mode on |
---|
After the configuration is complete, restart vsftpd, and the active mode is turned on
1 2 3 4 5 6 7 8 910111213141516171819202122232425 | listen=NOlisten_ipv6=YESanonymous_enable=NOlocal_enable=YESdirmessage_enable=YESuse_localtime=YESxferlog_enable=YESxferlog_file=/var/log/vsftpd.logxferlog_std_format=YESanonymous_enable=NOlocal_enable=YESdirmessage_enable=YESuse_localtime=YESxferlog_enable=YESxferlog_file=/var/log/vsftpd.logxferlog_std_format=YESsecure_chroot_dir=/var/etc-slakes-certam/ .pemrsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.keyssl_enable=NOchroot_local_user=YESallow_writeable_chroot=YESwrite_enable=YESlocal_root=/data/storagelocal_umask=0file_open_YES=0666pasv_enable=YESsvpassive_min_ports_min_passive_max_ports_min_pasv_enable=YES250 Security check in mode |
---|
Use filezilla or a browser to directly access the ftp://ftp address, we use curl here to upload and download
1 ) Create multiple files
1 | for i in seq 1 100 ;do echo "num: |
---|
2 ) Upload multiple files
1 | for i in seq 1 100 ;do curl -u ftpadmin:Tccm2008 -T upload_$i.log ftp://10.0.3.111 ;done |
---|
3 ) Download multiple files
1 | for i in seq 1 100 ;do curl ftp://10.0.3.111/upload_ |
---|
Recommended Posts