python FTP服务器实现(Python3)

2018-12-25 08:24:33来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

创建一个ftp.py文件(Linux环境),插入以下代码:

from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer

# 实例化DummyAuthorizer来创建ftp用户
authorizer = DummyAuthorizer()
# 参数:用户名,密码,目录,权限
authorizer.add_user('test', '12345', '/root/ftp', perm='elradfmwMT')
authorizer.add_user('tese1', '12345', '/root/ftp', perm='elradfmwMT')
# 匿名登录
# authorizer.add_anonymous('/home/nobody')

handler = FTPHandler
handler.authorizer = authorizer

# 参数:IP,端口,handler
server = FTPServer(('172.31.8.88', 21), handler)
server.serve_forever()

###### 文件保存
:wq 保存文件

###### 运行:

root@k8s-node1 ~]# nohup python3 ftp.py &
[1] 1737
[root@k8s-node1 ~]# nohup: 忽略输入并把输出追加到"nohup.out"
[root@k8s-node1 ~]# root@k8s-node1 ~]# tail -f nohup.out
[I 2018-11-30 12:52:03] 172.31.8.3:52635-[test] USER 'test' logged in.
[I 2018-11-30 12:57:03] 172.31.8.3:52635-[test] Control connection timed out.
[I 2018-11-30 12:57:03] 172.31.8.3:52635-[test] FTP session closed (disconnect).
[I 2018-12-20 09:36:26] >>> starting FTP server on 172.31.8.88:21, pid=1737 <<<
[I 2018-12-20 09:36:26] concurrency model: async
[I 2018-12-20 09:36:26] masquerade (NAT) address: None
[I 2018-12-20 09:36:26] passive ports: None
[I 2018-12-20 09:36:49] 172.31.8.3:52150-[] FTP session opened (connect)
[I 2018-12-20 09:36:52] 172.31.8.3:52150-[] USER 'anonymous' failed login.
[I 2018-12-20 09:36:52] 172.31.8.3:52150-[] FTP session closed (disconnect).
[I 2018-12-20 09:37:09] 172.31.8.3:52156-[] FTP session opened (connect)
[I 2018-12-20 09:37:12] 172.31.8.3:52156-[] USER 'test' failed login.
[I 2018-12-20 09:37:12] 172.31.8.3:52156-[] FTP session closed (disconnect).
[I 2018-12-20 09:37:16] 172.31.8.3:52159-[] FTP session opened (connect)
[I 2018-12-20 09:37:16] 172.31.8.3:52159-[test] USER 'test' logged in.
[I 2018-12-20 09:37:16] 172.31.8.3:52159-[test] FTP session closed (disconnect).
[I 2018-12-20 09:37:16] 172.31.8.3:52160-[] FTP session opened (connect)
[I 2018-12-20 09:37:16] 172.31.8.3:52160-[test] USER 'test' logged in.
[I 2018-12-20 09:40:13] 172.31.8.3:52160-[test] FTP session closed (disconnect).

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Scrapy at a glance预览

下一篇:python面向对象(C3算法)(六)