我正在使用 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
我的代码(主要是从教程中粘贴的):
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 处理程序类与 TLS 一起工作?