FTP file transfer protocol (to realize the mutual transfer of windows and linux files)

FTP file transfer protocol (to realize the mutual transfer of windows and linux files)

1. FTP overview

File transfer protocol (FTP), based on which FTP client and server can
share files, upload files, and download files. FTP generates a virtual connection based on the TCP protocol, which is mainly used to control
FTP connection information, and at the same time, it generates a separate TCP connection for FTP data transmission. Users can
upload, download, and delete files to the FTP server through the client, and the FTP server can be shared by multiple people at the same time.
The FTP service is a client/server (C/S for short) mode. The software that realizes the external sharing and transmission of FTP files based on the FTP protocol is called the FTP server source side. The client program is based on the FTP protocol, so it is called the FTP client. The client can upload and download files to the FTP server.

2. FTP communication port

The FTP server is used TCP协议的20、21端口by the client to communicate by default.
Port 20 is used to establish a data connection and transfer file data.
Port 21 is used to establish a control connection and transfer FTP control commands.

3. FTP data connection

FTP data connection is divided into 主动模式和被动模式
active mode: the server actively initiates the data connection
Passive mode: the server passively waits for the data connection

Four, FTP connection experiment in detail

1. Experimental environment: virtual machine Centos7, virtual machine Windows10

(1), install the vfstp installation package

yum install -y vsftpd
cd /etc/vsftpd/
cp vsftpd.conf vsftpd.conf.bak #备份配置文件

Insert picture description here
Insert picture description here

(2) Set up FTP service accessed by anonymous users (maximum authority)

(1) Modify the configuration file

vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES #开启匿名用户访问。默认已开启
write_enable=YES #开放服务器的写权限(若要上传,必须开启)。默认已开启
anon_umask=022 #设置匿名用户所上传数据的权限掩码(反掩码)。默认已开启
anon_upload_enable=YES #允许匿名用户上传文件。默认已注释,需取消注释
anon_mkdir_write_enable=YES #允许匿名用户创建(上传)目录。默认已注释,需取消注释
anon_other_write_enable =YES #允许删除、重命名、覆盖等操作。需添加

Insert picture description here

(2) Set maximum permissions for anonymous access to the pub subdirectory under the root directory of ftp, so that anonymous users can upload data

chmod 777 /var/ftp/pub/

Insert picture description here

(3) Turn on the service, turn off the firewall and enhanced security functions

systemctl start vsftpd
systemctl stop firewalld
setenforce 0

(4) Anonymous access test

Open the start menu in the Windows system, enter the cmd command to open the command prompt

Establish ftp connection: ftp 192.168.126.10 (virtual machine ip address)

#Anonymous access, the username is ftp, the password is empty, just press Enter to complete the login
ftp> pwd #匿名访问ftp的根目录为Linux系统的/var/ftp/目录
ftp> ls #查看当前目录
ftp> cd pub #切换到pub 目录
ftp> get 文件名 #下载文件到当前Windows本地目录 ftp> put 文件名 #上传文件到ftp目录
ftp> quit #退出

Insert picture description here

Insert picture description here

Insert picture description here

Open the virtual machine win10 below, download and try

Insert picture description here

Insert picture description here

Insert picture description here

Let's try to create a file on win10, can it be uploaded to the virtual machine centos7

Insert picture description here

Insert picture description here

Insert picture description here

2. Set local user authentication to access ftp, and prohibit switching to directories other than ftp (default login root directory is the home directory of the local user)

Virtual machine CentOS7

1. Modify the configuration file

vim /etc/vsftpd/vsftpd.conf
local_enable=Yes #启用本地用户
anonymous_enable=NO #关闭匿名用户访问
write_enable=YES #开放服务器的写权限(若要上传,必须开启)
anon_umask=077 #可设置仅宿主用户拥有被上传的文件的权限(反掩码)
chroot_local_user=YES #将访问禁锢在用户的宿主目录中
allow_writeable_chroot=YES #允许被限制的用户主目录具有写权限

Insert picture description here

Insert picture description here

2. Restart the service
systemctl restart vsftpd

3. Create users for easy verification

[root@localhost pub]#useradd lisi` `[root@localhost pub]#passwd lisi

Insert picture description here

Virtual machine win10, use win10 verification
Insert picture description here

Virtual machine CentOS7

Insert picture description here

Virtual machine win10

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_51573771/article/details/111143842