windows连接到linux上的FTP服务器进行文件传输

windows连接到linux上的FTP服务器进行文件传输

1 centos7 上安装ftp

检查是否安装了vsftpd
rpm –qa | grep vsftpd
在这里插入图片描述
如果没有信息显示,说明没有安装,使用yum安装:

yum install vsftpd –y

2 配置selinux

VSFTPD是一个FTP服务器程序,然后SELinux是CentOS的防火墙组件。由于 vsftpd 默认被 SELinux 拦截,所以会遇到访问FTP出现以下的问题:

226 Transfer done (but failed to open directory).(传输完成,但是打开路径失败)
550 Failed to change directory(更改路径失败)
553 Could not create file.
vim /etc/sysconfig/selinux

在这里插入图片描述

3 配置 FTP 权限

vim /etc/vsftpd/vsftpd.conf

找到或更改以下内容

# 禁用匿名用户
anonymous_enable=NO

# 禁止切换根目录
chroot_local_user=YES

# 设置FTP主目录
local_root=/data/ftp

# 配置FTP被动模式的端口
pasv_min_port=30000
pasv_max_port=30000

修改配置后,重新启动 FTP 服务,让配置生效

#停止该服务
systemctl stop vsftpd.service

#启动该服务
systemctl start vsftpd.service

#重启该服务
systemctl restart vsftpd.service

#查看该服务状态
systemctl status vsftpd.service

4 创建 FTP 用户

  • 创建用户

    useradd [用户名]
    #如 useradd user
    
  • 为用户设置密码

    echo "密码" | passwd [用户名] --stdin
    #如echo "123456" | passwd user --stdin
    
  • 限制该用户仅能通过 FTP 访问

    usermod -s /sbin/nologin [用户名]
    

    限制用户 user1只能通过 FTP 访问服务器,而不能直接登录服务器

  • 为用户分配主目录

    # 创建目录:
    mkdir -p /data/ftp/pub
    
    # 创建登录欢迎说明文件:
    echo "Welcome to use FTP service." > /data/ftp/welcome.txt
    
    # 设置访问权限:
    chmod a-w /data/ftp && chmod 777 -R /data/ftp/pub
    
    # 设置为用户的主目录: 即用户通过 FTP 登录后看到的根目录
    usermod -d /data/ftp [用户名]
    

5 配置防火墙

#开放端口号
firewall-cmd --add-port=20/tcp --permanent
firewall-cmd --add-port=21/tcp --permanent

#查看指定端口是否开放
firewall-cmd --query-port=21/tcp

#查看所有开放的端口号
firewall-cmd --list-ports

#重启防火墙
firewall-cmd --reload

6 cmd传输文件

C:\Windows\System32>ftp
ftp> open 192.168.31.31
连接到 192.168.31.31。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
用户(192.168.31.31:(none)): YanXxx
331 Please specify the password.
密码:
230 Login successful.


ftp> dir
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x    2 0        0               6 Mar 25 06:32 pub
drwxrwxrwx    2 14       50              6 Mar 25 08:24 upload
-rwxr-xr-x    1 0        0              28 Mar 25 06:32 welcome.txt
226 Directory send OK.
ftp: 收到 197 字节,用时 0.0211.59千字节/秒。
ftp> lcd
目前的本地目录 C:\Windows\System32。
ftp> lcd D:\software\SERVU\test
目前的本地目录 D:\software\SERVU\test。

#下载文件welcome.txt
ftp> get welcome.txt
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for welcome.txt (28 bytes).
226 Transfer complete.
ftp: 收到 28 字节,用时 0.0028.00千字节/秒。
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
pub
upload
welcome.txt
226 Directory send OK.
ftp: 收到 29 字节,用时 0.007.25千字节/秒。

#上传文件
ftp> cd upload
250 Directory successfully changed.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory send OK.

ftp> put a.txt
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
ftp: 发送 7 字节,用时 0.007000.00千字节/秒。
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
a.txt
226 Directory send OK.
ftp: 收到 10 字节,用时 0.0010.00千字节/秒。

在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值