我正在使用pyftpdlib来制作自定义FTP服务器。我需要支持TLS以及带宽限制,这两者都在教程文档中介绍。但是,当我尝试一起使用它们时,当我尝试连接FileZilla时出现错误:
Status: Resolving address of localhost
Status: Connecting to [::1]:2121...
Status: Connection established, waiting for welcome message...
Status: Initializing TLS...
Status: Verifying certificate...
Status: TLS connection established.
Status: Logged in
Status: Retrieving directory listing...
Command: PWD
Response: 257 "/" is the current directory.
Command: TYPE I
Response: 200 Type set to: Binary.
Command: EPSV
Response: 229 Entering extended passive mode (|||9527|).
Command: MLSD
Response: 150 File status okay. About to open data connection.
**Error: GnuTLS error -15: An unexpected TLS packet was received.**
Error: Transfer connection interrupted: ECONNABORTED - Connection aborted
Response: 226 Transfer complete.
Error: Failed to retrieve directory listing
我的代码(大多只是从tutorial粘贴):
import os
from pyftpdlib.handlers import TLS_FTPHandler, ThrottledDTPHandler
from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import DummyAuthorizer
def main():
authorizer = DummyAuthorizer()
authorizer.add_user('user', '12345', os.getcwd(), perm='elradfmw')
authorizer.add_anonymous(os.getcwd())
dtp_handler = ThrottledDTPHandler
dtp_handler.read_limit = 30720 # 30 Kb/sec (30 * 1024)
dtp_handler.write_limit = 30720 # 30 Kb/sec (30 * 1024)
ftp_handler = TLS_FTPHandler
ftp_handler.authorizer = authorizer
ftp_handler.certfile = "C:\\temp\\certificates\\test.pem"
# have the ftp handler use the alternative dtp handler class
ftp_handler.dtp_handler = dtp_handler
server = FTPServer(('', 2121), ftp_handler)
server.serve_forever()
if __name__ == '__main__':
main()
如果我拿出这条线:
ftp_handler.dtp_handler = dtp_handler
我可以连接,但这当然会消除限制。
有没有办法让DTP Handler类与TLS一起使用?