码迷,mamicode.com
首页 > 编程语言 > 详细

python 用pyftplib快速建设ftp

时间:2015-07-27 23:08:36      阅读:489      评论:0      收藏:0      [点我收藏+]

标签:

先下载


 svn checkout http://pysendfile.googlecode.com/svn/ pysendfile-read-only

cd pysendfile-read-only/  

 python setup.py build

python setup.py install

 svn checkout http://pyftpdlib.googlecode.com/svn/trunk/ pyftpdlib-read-only 

 cd pyftpdlib-read-only/

 python setup.py build
python setup.py install


vim ftpserver.py

#!/usr/bin/env python
from pyftpdlib import ftpserver
authorizer = ftpserver.DummyAuthorizer()
authorizer.add_user("user", "12345", "/home/great", perm="elradfmw")
authorizer.add_anonymous("/home/great")
handler = ftpserver.FTPHandler
handler.authorizer = authorizer
address = ("127.0.0.1", 21)
ftpd = ftpserver.FTPServer(address, handler)
ftpd.serve_forever()

python ftpserver.py

  别人的代码

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 = ('', 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()

文档

http://pythonhosted.org/pyftpdlib/index.html

版权声明:本文为博主原创文章,未经博主允许不得转载。

python 用pyftplib快速建设ftp

标签:

原文地址:http://blog.csdn.net/ssihc0/article/details/47091039

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!