Created
October 4, 2017 10:38
-
-
Save blippy/8a963e3d614eea4223c97b745663fc12 to your computer and use it in GitHub Desktop.
Personal FTP server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import os | |
| from pyftpdlib.authorizers import DummyAuthorizer | |
| from pyftpdlib.handlers import FTPHandler | |
| from pyftpdlib.servers import FTPServer | |
| def main(): | |
| # Instantiate a dummy authorizer for managing 'virtual' users | |
| authorizer = DummyAuthorizer() | |
| # Define a new user having full r/w permissions and a read-only | |
| # anonymous user | |
| authorizer.add_user('user', '12345', '.', perm='elradfmwM') | |
| authorizer.add_anonymous(os.getcwd()) | |
| # Instantiate FTP handler class | |
| handler = FTPHandler | |
| handler.authorizer = authorizer | |
| # Define a customized banner (string returned when client connects) | |
| handler.banner = "pyftpdlib based ftpd ready." | |
| # Specify a masquerade address and the range of ports to use for | |
| # passive connections. Decomment in case you're behind a NAT. | |
| #handler.masquerade_address = '151.25.42.11' | |
| #handler.passive_ports = range(60000, 65535) | |
| # Instantiate FTP server class and listen on 0.0.0.0:2121 | |
| address = ('', 2121) | |
| server = FTPServer(address, handler) | |
| # set a limit for connections | |
| server.max_cons = 256 | |
| server.max_cons_per_ip = 5 | |
| # start ftp server | |
| server.serve_forever() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment