Skip to content

Instantly share code, notes, and snippets.

@willnix
Created May 17, 2019 11:22
Show Gist options
  • Save willnix/3e2f795f4586c32c23b6b6ac666cc520 to your computer and use it in GitHub Desktop.
Save willnix/3e2f795f4586c32c23b6b6ac666cc520 to your computer and use it in GitHub Desktop.
Simple FTP server that accepts any credentials and logs the to stdout
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
from pyftpdlib.log import logger
HOMEDIR = "/var/ftp"
# Authorizer granting access to everyone and logging the credentials
class LoggingAuthorizer(DummyAuthorizer):
def validate_authentication(self, username, password, handler):
# Add user on the fly if it does not exist yet
if not self.has_user(username):
self.add_user(username, password, HOMEDIR, perm="elradfmwMT")
# Log the credentials
logger.info('LOGIN User: "%s" - Password: "%s"' % (username, password))
authorizer = LoggingAuthorizer()
handler = FTPHandler
handler.authorizer = authorizer
server = FTPServer(("0.0.0.0", 2121), handler)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment