博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python FTP服务器实现(Python3)
阅读量:4308 次
发布时间:2019-06-06

本文共 2172 字,大约阅读时间需要 7 分钟。

创建一个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).

转载于:https://www.cnblogs.com/ArchitecTang/p/10174065.html

你可能感兴趣的文章
[转]gcc生成动态库静态库
查看>>
js 类数组arguments详解
查看>>
前段技术学习计划
查看>>
隐藏GridControl的“Drag a column header here to group by that column”
查看>>
安卓UI测试(基于android studio环境 espresso框架)
查看>>
iOS 获取当前对象所在的VC
查看>>
[译]如何在visual studio中调试Javascript
查看>>
expect
查看>>
Swift3.0语言教程获取C字符串
查看>>
XamarinAndroid组件教程RecylerView适配器设置动画示例
查看>>
Shell 示例:利用 $RANDOM 产生随机整数
查看>>
网络基础
查看>>
海量数据处理之倒排索引
查看>>
Repeater\DataList\GridView实现分页,数据编辑与删除
查看>>
software testing hw2- find the error
查看>>
maven系列一:pom.xml文件详解
查看>>
Python基础实践-密码管理系统实例
查看>>
iOS工作笔记之NSClassFromString
查看>>
PING检查网络是否畅通
查看>>
李宁-2015年7月13日-个人文档
查看>>