状态:好饿啊
系统:宿主机为win10,VMware为CentOS8
条件:ftp服务器搭建在CentOS8中,已安装python3
目标:使win10能通过CentOS8的IP地址访问上面的ftp服务器
pip install pyftpdlib
或者
pip3 install pyftpdlib
具体情况看你的设置,我用的pip3
输入
python3 -m pyftpdlib
或者
python -m pyftpdlib
具体情况看设置,我用的python3
出现下图,进入虚拟机浏览器输入ftp://127.0.0.1:2121就能看见共享目录下的文件了,点击可以下载
编写一个python脚本,输入如下代码
-*- coding:utf-8 -*-
import os
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
def main():
# Instantiate a dummy authorizer for managing 'virtual' users
authorizer = DummyAuthorizer()
# Define a new user having full r/w permissions and a read-only
# anonymous user
authorizer.add_user('user', '12345', '.', perm='elradfmwM')
# authorizer.add_anonymous(os.getcwd())
# Instantiate FTP handler class
handler = FTPHandler
handler.authorizer = authorizer
# Define a customized banner (string returned when client connects)
handler.banner = "pyftpdlib based ftpd ready."
# Specify a masquerade address and the range of ports to use for
# passive connections. Decomment in case you're behind a NAT.
#handler.masquerade_address = '151.25.42.11'
#handler.passive_ports = range(60000, 65535)
# Instantiate FTP server class and listen on 0.0.0.0:2121
address = ('192.168.153.132', 2121)
server = FTPServer(address, handler)
# set a limit for connections
server.max_cons = 256
server.max_cons_per_ip = 5
# start ftp server
server.serve_forever()
if __name__ == '__main__':
main()
第一个箭头:设置了用户名密码,可以去掉然后把下面一行注释取消,就能匿名登陆了
第二个箭头:换成你自己虚拟机中的ip,端口默认为2121,可以自己设置
查看防火墙状态
firewall-cmd --state
停止防火墙
systemctl stop firewalld.service
OK啦,退出ftp按ctrl-C就好啦
怎么让它一直运行我还没试,但目前就到此为止吧
噜啦啦啦啦啦
https://blog.csdn.net/whiterbear/article/details/50094489
https://my.oschina.net/kangvcar/blog/1599867