0

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?

Bruce Van Horn
  • 613
  • 2
  • 6
  • 14
  • From this [discusssion/thread](https://groups.google.com/forum/#!topic/pyftpdlib/5nXT4U9Tm_A) on the `pyftpdlib` mailing list, it looks like you'll need a small class which mixes the `ThrottledDTPHandler` and `TLS_DTPHandler` classes. – Castaglia Mar 22 '16 at 18:31
  • It suggests multiple inheritance, and I don't have any scotch. – Bruce Van Horn Mar 23 '16 at 04:43
  • I'm not sure what you mean by "I don't have any scotch", sorry. One of the emails in that thread suggests creating a class which maxes the two `DTPHandlers` like so: `class MixedHandler(ThrottledDTPHandler, TLS_DTPHandler):` (_e.g._ before the `main` method), and then using that class: `dtp_handler = MixedHandler`. Does that help? – Castaglia Mar 23 '16 at 05:16

0 Answers0