I can make a basic FTP server that answers port 21 (or in this example 2121) using the sample from the documentation:
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
from pyftpdlib.contrib.authorizers import WindowsAuthorizer
def main():
authorizer = WindowsAuthorizer()
# Use Guest user with empty password to handle anonymous sessions.
# Guest user must be enabled first, empty password set and profile
# directory specified.
#authorizer = WindowsAuthorizer(anonymous_user="Guest", anonymous_password="")
handler = FTPHandler
handler.authorizer = authorizer
server = FTPServer(('', 2121), handler)
server.serve_forever()
if __name__ == "__main__":
main()
Or I can make one that supports TLS (again this is the sample from the docs, except our secure FTP port is 990, not 21 as shown in the original code sample):
from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.contrib.handlers import TLS_FTPHandler
def main():
authorizer = DummyAuthorizer()
authorizer.add_user('user', '12345', '.', perm='elradfmw')
authorizer.add_anonymous('.')
handler = TLS_FTPHandler
handler.certfile = 'keycert.pem'
handler.authorizer = authorizer
# requires SSL for both control and data channel
#handler.tls_control_required = True
#handler.tls_data_required = True
server = FTPServer(('', 990), handler)
server.serve_forever()
if __name__ == '__main__':
main()
Is there a way to make one that answers port 21 (insecure) AND 990 (secured with TLS) in the same script where they share a range of passive ports, for example:
handler.passive_ports = range(50000, 50051)
I imagine I could write two scripts but how will it work if they share the passive port range? That range is a requirement and the current IIS setup we use supports both TLS and insecure connections. I want to use pyftpdlib in a customized server so we can perform custom logic on uploaded files. All that works fine, I just need to understand this last bit and I'm not experienced in writing FTP servers.