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).

  • 相关阅读:
    自动配置原理5
    JSR303数据校验4
    mysql 安装(压缩包安装和exe安装)
    jQuery关于复制(复制隐藏文字+显示文字)跳转,Clipboard
    html页面设置一个跟随鼠标移动的DIV(jQuery实现)
    js中将时间(如:2017-10-8 22:44:55)转化为时间搓,时间戳转为标准格式时间
    异常:java.lang.IllegalArgumentException: Control character in cookie value or attribute.
    从数据库导出数据到excel之List<List<Object>>导出
    从数据库导出数据到excel之List<map>导出
    从数据库导出数据到excel之POI操作
  • 原文地址:https://www.cnblogs.com/ArchitecTang/p/10174065.html
Copyright © 2011-2022 走看看