Created
March 28, 2021 13:47
-
-
Save ichisadashioko/6012395955e1e6fc2c1ce790ab123a36 to your computer and use it in GitHub Desktop.
quickly sprung up a ftp server for accessing files from other devices in the network
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
| pyftpdlib |
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
| import os | |
| import argparse | |
| from pyftpdlib.authorizers import DummyAuthorizer | |
| from pyftpdlib.handlers import FTPHandler | |
| from pyftpdlib.servers import FTPServer, ThreadedFTPServer | |
| if __name__ == '__main__': | |
| parser = argparse.ArgumentParser(description='Simple FTP server.') | |
| parser.add_argument( | |
| 'port', | |
| default=21, | |
| type=int, | |
| help='port number', | |
| nargs='?', | |
| ) | |
| parser.add_argument( | |
| 'local_path', | |
| nargs='?', | |
| default='.', | |
| type=str, | |
| help='root directory to serve', | |
| ) | |
| args = parser.parse_args() | |
| print(args) | |
| port = args.port | |
| local_path = args.local_path | |
| if not os.path.exists(local_path): | |
| raise Exception(f'{local_path} does not exist!') | |
| authorizer = DummyAuthorizer() | |
| # authorizer.add_user('username', 'password', local_path, perm='elr') | |
| authorizer.add_anonymous(local_path) | |
| handler = FTPHandler | |
| handler.authorizer = authorizer | |
| # server = ThreadedFTPServer(('0.0.0.0', port), handler) | |
| server = FTPServer(('0.0.0.0', port), handler) | |
| server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment