zoukankan      html  css  js  c++  java
  • python FTP服务器实现(Python3)

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

  • 相关阅读:
    valgrind的使用
    php开启gzip压缩
    scrapy
    今天几个bug的排查过程
    awk使用多个分割符
    有用的url
    图片延迟加载
    用中间表提高互联网程序的开发效率
    百度技术沙龙
    vs2005/.NET2.0 控件演示之 文件上传 《FileUpload》
  • 原文地址:https://www.cnblogs.com/ArchitecTang/p/10174065.html
Copyright © 2011-2022 走看看