1、ftp服务
-
工作原理
-
客户端向服务器发送请求、同时客户端系统动态的打开一个大于1024的端口等待服务器连接
-
若FTP服务器在端口21侦听到该请求、则会在客户端1031端口和服务器的21端口之间建立一个FTP会话连接
-
当需要传输数据时、FTP客户端再动态的打开一个大于1024的端口(比如1032端口)连接到服务器的20端口,并再这两个端口之间传输数据。当数据传输完毕,这两个端口会自动关闭。
-
数据传输完毕,如果客户端不向服务端发送拆除连接的请求,则继续保持连接
-
当FTP客户端向服务端发送拆除连接的请求并确认后、客户端将端口与FTP服务的连接,客户端上动态分配的端口将自动释放。
-
-
参数
选项 | 说明 |
---|---|
anonymous_enable | 设置是否允许匿名用户登录 |
local_enable | 设置是否允许本地用户登录 |
anon_upload_enable | 允许匿名用户上传文件 |
anon_mkdir_write_enable | 允许匿名用户创建文件 |
anon_other_write_enable | 允许匿名用户修改目录或者删除目录 |
2、服务端操作
# 安装包
[root@test01 /]# yum -y install vsftpd
# 创建共享目录
# 因为ftp默认的情况下,根目录下,有w的权限的话,会连不上去,所以的话,只能连上去了才能加上w的权限,或者创建在根目录下创建一个upload文件夹,专门用来上传文件的
[root@test01 /]# mkdir -p /share/ftp-share
[root@test01 /]# touch /share/ftp-share/ftp-flag
[root@test01 /]# mkdir -p /share/ftp-share/upload
[root@test01 /]# chmod 777 /share/ftp-share/upload/
[root@test01 /]# vim /etc/vsftpd/vsftpd.conf
anon_root=/share/ftp-share
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
[root@test01 /]# systemctl enable vsftpd --now
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
# 安全放行
[root@test01 /]# firewall-cmd --permanent --add-service=ftp
success
[root@test01 /]# firewall-cmd --reload
success
[root@test01 /]# semanage boolean -l | grep ftp
ftpd_use_cifs (off , off) Allow ftpd to use cifs
ftpd_connect_db (off , off) Allow ftpd to connect db
ftpd_use_fusefs (off , off) Allow ftpd to use fusefs
ftpd_full_access (off , off) Allow ftpd to full access
tftp_anon_write (off , off) Allow tftp to anon write
tftp_home_dir (off , off) Allow tftp to home dir
httpd_can_connect_ftp (off , off) Allow httpd to can connect ftp
ftpd_use_passive_mode (off , off) Allow ftpd to use passive mode
ftpd_use_nfs (off , off) Allow ftpd to use nfs
ftpd_connect_all_unreserved (off , off) Allow ftpd to connect all unreserved
ftpd_anon_write (off , off) Allow ftpd to anon write
httpd_enable_ftp_server (off , off) Allow httpd to enable ftp server
[root@test01 /]# setsebool -P ftpd_full_access on
[root@test01 /]# setsebool -P ftpd_anon_write on
[root@test01 /]# semanage boolean -l | grep ftp
ftpd_use_cifs (off , off) Allow ftpd to use cifs
ftpd_connect_db (off , off) Allow ftpd to connect db
ftpd_use_fusefs (off , off) Allow ftpd to use fusefs
ftpd_full_access (on , on) Allow ftpd to full access
tftp_anon_write (off , off) Allow tftp to anon write
tftp_home_dir (off , off) Allow tftp to home dir
httpd_can_connect_ftp (off , off) Allow httpd to can connect ftp
ftpd_use_passive_mode (off , off) Allow ftpd to use passive mode
ftpd_use_nfs (off , off) Allow ftpd to use nfs
ftpd_connect_all_unreserved (off , off) Allow ftpd to connect all unreserved
ftpd_anon_write (on , on) Allow ftpd to anon write
httpd_enable_ftp_server (off , off) Allow httpd to enable ftp server
3、客户端操作
# 登录到的位置在10.104.43.154:/share/ftp-share这个目录下面
# 下载文件的位置在你登录的位置那
[root@test02 /]# lftp 10.104.43.154
lftp 10.104.43.154:~> ls
-rw-r--r-- 1 0 0 0 Sep 27 07:28 ftp-flag
drwxrwxrwx 2 0 0 6 Sep 27 07:28 upload
lftp 10.104.43.154:/> get ftp-flag