Skip to content

Instantly share code, notes, and snippets.

@ichisadashioko
Created March 28, 2021 13:47
Show Gist options
  • Select an option

  • Save ichisadashioko/6012395955e1e6fc2c1ce790ab123a36 to your computer and use it in GitHub Desktop.

Select an option

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
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