ftp_server.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import os
  2. from pyftpdlib.authorizers import DummyAuthorizer
  3. from pyftpdlib.handlers import FTPHandler
  4. from pyftpdlib.servers import FTPServer
  5. def main():
  6. # Instantiate a dummy authorizer for managing 'virtual' users
  7. authorizer = DummyAuthorizer()
  8. # Define a new user having full r/w permissions and a read-only
  9. # anonymous user
  10. authorizer.add_user('user', '12345', '.', perm='elradfmwMT')
  11. authorizer.add_anonymous(os.getcwd())
  12. # Instantiate FTP handler class
  13. handler = FTPHandler
  14. handler.authorizer = authorizer
  15. # Define a customized banner (string returned when client connects)
  16. handler.banner = "pyftpdlib based ftpd ready."
  17. # Specify a masquerade address and the range of ports to use for
  18. # passive connections. Decomment in case you're behind a NAT.
  19. #handler.masquerade_address = '151.25.42.11'
  20. #handler.passive_ports = range(60000, 65535)
  21. # Instantiate FTP server class and listen on 0.0.0.0:2121
  22. address = ('', 5121)
  23. server = FTPServer(address, handler)
  24. # set a limit for connections
  25. server.max_cons = 256
  26. server.max_cons_per_ip = 5
  27. # start ftp server
  28. server.serve_forever()
  29. if __name__ == '__main__':
  30. main()