前提是能连上公网
本文以redhat系列环境为例
1.FTP服务器安装
1.1 安装vsftpd
yum -y install vsftpd
1.2 修改配置文件
cd /etc/vsftpd
vi vsftpd.conf
-------------------------------------------配置文件
# 禁用匿名模式
anonymous_enable=NO
#
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES
#
#具有写权限
write_enable=YES
#
#本地用户创建文件或目录的掩码
local_umask=022
# Activate directory messages - messages given to remote users when they
dirmessage_enable=YES
#
#当设定为YES时,使用者上传与下载日志都会被纪录起来。记录日志与下一个xferlog_file设定选项有关
xferlog_enable=YES
xferlog_std_format=YESxferlog_file=/var/log/xferlog
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#chown_uploads=YES
#chown_username=whoever
#idle_session_timeout=600
#
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# async_abor_enable=YES
#
# ASCII mangling is a horrible feature of the protocol.
ascii_upload_enable=NO
ascii_download_enable=NO
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
chroot_local_user=YES
chroot_list_enable=YES
# (default follows)-该文件记得要有相应用户读写权限
chroot_list_file=/etc/vsftpd/chroot_list
#chroot_list_file=/data/ftp/
#ls_recurse_enable=YES
#
#listen=NO
#
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=NO
tcp_wrappers=YES
allow_writeable_chroot=YES
listen_port=8887
#FTP访问目录
local_root=/data/ftp/
#被动模pasv_enable=YES
#被动模式对外提供端口
pasv_min_port=65400
pasv_max_port=65410
1.3 新建用户和赋值权限
#新建用户
useradd ftptrm -s /sbin/nologin -d /data/ftp
#修改密码
passwd ftptrm
#修改权限 chown -R ftptrm /data/ftp
chmod o+w ftptrm /data/ftp
#修改用户
echo 'ftptrm' >> /etc/vsftpd/user_listcp /etc/vsftpd/user_list /etc/vsftpd/chroot_list#服务器的selinux被禁用
vim /etc/pam.d/vsftpd 注释掉如下内容 #auth required pam_shells.so
1.4 防火墙关闭(对外提供端口8887、65400-65410
systemctl stop firewalld
firewall-cmd --permanent --zone=public --add-port=8887/tcp
firewall-cmd --permanent --zone=public --add-port=65400-65410/tcp
firewall-cmd --reload #重新加载
firewall-cmd --zone=public --list-port #参考开发端口
#firewall-cmd --permanent --zone=public --remove-port=8886/tcp #禁用端口
1.5 启动服务
#开机启动
systemctl enable vsftpd.service
#重启服务
systemctl restart vsftpd.service
#启动
systemctl start vsftpd.service
#停止
systemctl stop vsftpd.service
#状态
systemctl status vsftpd.service
2.FTP客户端安装
yum -y install ftp #ftp安装
2.1 客户端连接命令
#连接 IP 端口
ftp 192.168.1.100 8887
#输入名称
ftp>name
#密码
ftp>password
#进入目录
ftp>cd /data/ftp
#下载本地
ftp>get test.txt#文件上传ftp>put myfile /data/ftp/