1#!/usr/local/bin/python3.8
2
3# Copyright (C) 2007 Giampaolo Rodola' <g.rodola@gmail.com>.
4# Use of this source code is governed by MIT license that can be
5# found in the LICENSE file.
6
7"""
8An FTP server which uses the ThrottledDTPHandler class for limiting the
9speed of downloads and uploads.
10"""
11
12import os
13
14from pyftpdlib.authorizers import DummyAuthorizer
15from pyftpdlib.handlers import FTPHandler
16from pyftpdlib.handlers import ThrottledDTPHandler
17from pyftpdlib.servers import FTPServer
18
19
20def main():
21    authorizer = DummyAuthorizer()
22    authorizer.add_user('user', '12345', os.getcwd(), perm='elradfmwMT')
23    authorizer.add_anonymous(os.getcwd())
24
25    dtp_handler = ThrottledDTPHandler
26    dtp_handler.read_limit = 30720  # 30 Kb/sec (30 * 1024)
27    dtp_handler.write_limit = 30720  # 30 Kb/sec (30 * 1024)
28
29    ftp_handler = FTPHandler
30    ftp_handler.authorizer = authorizer
31    # have the ftp handler use the alternative dtp handler class
32    ftp_handler.dtp_handler = dtp_handler
33
34    server = FTPServer(('', 2121), ftp_handler)
35    server.serve_forever()
36
37
38if __name__ == '__main__':
39    main()
40