Python的FTP服務器開發包 pyftpdlib

fmms 12年前發布 | 55K 次閱讀 Python 網絡工具包

Python的FTP服務器開發包 pyftpdlib
Python FTP server library (pyftpdlib) 提供了高級的便攜式的編程接口,用來實現異步的FTP服務器的功能。基本上實現了 RFC-959 規范。它支持的特性包括:

  • FTPS (FTP over TLS/SSL). New in 0.6.0
  • Support for recent FTP commands such as MLSD, MLST, EPSV and EPRT (RFC-3659).
  • Support for virtual users and virtual filesystem.
  • FXP site-to-site transfers.
  • IPv6 (RFC-2428) support.
  • Bandwidth throttling.
  • Per-user permissions configurability.
  • Maximum and per-ip connection limits.
  • Compact: main library is distributed as a single stand-alone module (ftpserver.py).
  • High portability:
    • Entirely written in pure Python, no third party modules are used. It works on any system where select( ) or poll( ) is available.
    • Extremely flexible system of "authorizers" able to manage both "virtual" and "real" users on on both Windows and UNIX.
    • Works with Python from 2.4 to 2.7.

示例代碼:

>>> from pyftpdlib import ftpserver
>>> authorizer = ftpserver.DummyAuthorizer()
>>> authorizer.add_user("user", "12345", "/home/user", perm="elradfmw")
>>> authorizer.add_anonymous("/home/nobody")
>>> handler = ftpserver.FTPHandler
>>> handler.authorizer = authorizer
>>> address = ("127.0.0.1", 21)
>>> ftpd = ftpserver.FTPServer(address, handler)
>>> ftpd.serve_forever()
Serving FTP on 127.0.0.1:21
[]127.0.0.1:2503 connected.
127.0.0.1:2503 ==> 220 Ready.
127.0.0.1:2503 <== USER anonymous
127.0.0.1:2503 ==> 331 Username ok, send password.
127.0.0.1:2503 <== PASS ******
127.0.0.1:2503 ==> 230 Login successful.
[anonymous]@127.0.0.1:2503 User anonymous logged in.
127.0.0.1:2503 <== TYPE A
127.0.0.1:2503 ==> 200 Type set to: ASCII.
127.0.0.1:2503 <== PASV
127.0.0.1:2503 ==> 227 Entering passive mode (127,0,0,1,9,201).
127.0.0.1:2503 <== LIST
127.0.0.1:2503 ==> 150 File status okay. About to open data connection.
[anonymous]@127.0.0.1:2503 OK LIST "/". Transfer starting.
127.0.0.1:2503 ==> 226 Transfer complete.
[anonymous]@127.0.0.1:2503 Transfer complete. 706 bytes transmitted.
127.0.0.1:2503 <== QUIT
127.0.0.1:2503 ==> 221 Goodbye.
[anonymous]@127.0.0.1:2503 Disconnected.

項目主頁:http://www.baiduhome.net/lib/view/home/1326808627280

 本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!