Skip to content

Instantly share code, notes, and snippets.

@wlinds
Created May 1, 2024 10:55
Show Gist options
  • Save wlinds/437a6abf3369e005d2cc5ca40aee1869 to your computer and use it in GitHub Desktop.
Save wlinds/437a6abf3369e005d2cc5ca40aee1869 to your computer and use it in GitHub Desktop.
Super simple asynchronous FTP server with pyftpdlib
import os
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
USERNAME = "admin"
PASSWORD = "foobar"
PERMISSION = 'elradfmwMT'
# Read permission
# "e" = change directory (CWD, CDUP commands)
# "l" = list files (LIST, NLST, STAT, MLSD, MLST, SIZE commands)
# "r" = retrieve file from the server (RETR command)
# Write permissions:
# "a" = append data to an existing file (APPE command)
# "d" = delete file or directory (DELE, RMD commands)
# "f" = rename file or directory (RNFR, RNTO commands)
# "m" = create directory (MKD command)
# "w" = store a file to the server (STOR, STOU commands)
# "M" = change file mode / permission (SITE CHMOD command)
# "T" = change file modification time (SITE MFMT command)
PATH = "Documents/Drum Sample" # Change this to your own preference
def main():
authorizer = DummyAuthorizer()
shared_dir = os.path.abspath(PATH)
authorizer.add_user(USERNAME, PASSWORD, shared_dir, perm=PERMISSION)
authorizer.add_anonymous(shared_dir)
handler = FTPHandler
handler.authorizer = authorizer
handler.passive_ports = range(60000, 65535)
handler.masquerade_address = 'external'
# Init FTP server class, listen on 0.0.0.0:2121
address = ('', 2121)
server = FTPServer(address, handler)
server.max_cons, server.max_cons_per_ip = 64, 20
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