Python的FTP服务器开发包 pyftpdlib
fmms
13年前
<p><img title="Python的FTP服务器开发包 pyftpdlib" border="0" alt="Python的FTP服务器开发包 pyftpdlib" src="https://simg.open-open.com/show/58f710a700e97cbb5f2a70c94add71d4.png" width="147" height="55" /><br /> Python FTP server library (pyftpdlib) 提供了高级的便携式的编程接口,用来实现异步的FTP服务器的功能。基本上实现了 RFC-959 规范。它支持的特性包括:</p> <ul> <li><strong><a href="/misc/goto?guid=4959500978896983682" rel="nofollow">FTPS</a></strong> (FTP over TLS/SSL). <i><strong>New in 0.6.0</strong></i> </li> <li>Support for recent FTP commands such as <strong>MLSD</strong>, <strong>MLST</strong>, <strong>EPSV</strong> and <strong>EPRT</strong> (<a href="/misc/goto?guid=4959500978981000049" rel="nofollow">RFC-3659</a>). </li> <li>Support for virtual users and virtual filesystem. </li> <li><strong><a href="/misc/goto?guid=4959500979062756125" rel="nofollow">FXP</a></strong> site-to-site transfers. </li> <li><strong>IPv6</strong> (<a href="/misc/goto?guid=4959500979257532728" rel="nofollow">RFC-2428</a>) support. </li> <li>Bandwidth throttling. </li> <li>Per-user permissions configurability. </li> <li>Maximum and per-ip connection limits. </li> <li>Compact: main library is distributed as a single stand-alone module (<a href="/misc/goto?guid=4959500979332823391" rel="nofollow">ftpserver.py</a>). </li> <li>High portability: </li> <ul> <li>Entirely written in pure Python, no third party modules are used. It works on any system where <i>select( )</i> or <i>poll( )</i> is available. </li> <li>Extremely flexible system of "authorizers" able to manage both "virtual" and "real" users on on both <strong>Windows</strong> and <strong>UNIX</strong>. </li> <li>Works with Python from <strong>2.4</strong> to <strong>2.7</strong>. </li> </ul> </ul> <p></p> <p>示例代码:</p> <pre class="brush:python; toolbar: true; auto-links: false;">>>> 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.</pre> <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1326808627280" target="_blank">http://www.open-open.com/lib/view/home/1326808627280</a></p> <p></p>