I am using pyftpdlib to make a custom FTP server. I need to support TLS as well as bandwidth throttling, both of which are covered in the tutorial documentation. However when I try to use them together I get an error when I try to connect with 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
My code (mostly just pasted from the 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()
if I take out the line:
ftp_handler.dtp_handler = dtp_handler
I can connect, but that of course removes throttling.
Is there a way to get the DTP Handler class to work with TLS?