Advertisement
knoppies

basic_ftpd.py

Mar 20th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.15 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # $Id$
  3.  
  4. #  pyftpdlib is released under the MIT license, reproduced below:
  5. #  ======================================================================
  6. #  Copyright (C) 2007-2013 Giampaolo Rodola' <g.rodola@gmail.com>
  7. #
  8. #                         All Rights Reserved
  9. #
  10. # Permission is hereby granted, free of charge, to any person
  11. # obtaining a copy of this software and associated documentation
  12. # files (the "Software"), to deal in the Software without
  13. # restriction, including without limitation the rights to use,
  14. # copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. # copies of the Software, and to permit persons to whom the
  16. # Software is furnished to do so, subject to the following
  17. # conditions:
  18. #
  19. # The above copyright notice and this permission notice shall be
  20. # included in all copies or substantial portions of the Software.
  21. #
  22. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  24. # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  26. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  27. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  28. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  29. # OTHER DEALINGS IN THE SOFTWARE.
  30. #
  31. #  ======================================================================
  32.  
  33. """A basic FTP server which uses a DummyAuthorizer for managing 'virtual
  34. users', setting a limit for incoming connections.
  35. """
  36.  
  37. import os
  38.  
  39. from pyftpdlib.authorizers import DummyAuthorizer
  40. from pyftpdlib.handlers import FTPHandler
  41. from pyftpdlib.servers import FTPServer
  42.  
  43.  
  44. def main():
  45.     # Instantiate a dummy authorizer for managing 'virtual' users
  46.     authorizer = DummyAuthorizer()
  47.  
  48.     # Define a new user having full r/w permissions and a read-only
  49.     # anonymous user
  50.     #authorizer.add_user('user', '12345', os.getcwd(), perm='elradfmwM')
  51.     #authorizer.add_anonymous(os.getcwd())
  52.     authorizer.add_user('user1', 'password', "/home/user1/", perm='elradfmw') # removed M from perms
  53.     authorizer.add_user('external', 'password', "/media/external", perm='elradfmw') # removed M from perms
  54.     #authorizer.add_user('rootUser', 'password', "/", perm='elradfmw') # root dir.
  55.  
  56.     # Instantiate FTP handler class
  57.     handler = FTPHandler
  58.     handler.authorizer = authorizer
  59.  
  60.     # Define a customized banner (string returned when client connects)
  61.     handler.banner = "FTP server for LAN file transfers."
  62.  
  63.     # Specify a masquerade address and the range of ports to use for
  64.     # passive connections.  Decomment in case you're behind a NAT.
  65.     #handler.masquerade_address = '151.25.42.11'
  66.     #handler.passive_ports = range(60000, 65535)
  67.  
  68.     # Instantiate FTP server class and listen on 0.0.0.0:2121
  69.     address = ('', 2121)
  70.     server = FTPServer(address, handler)
  71.  
  72.     # set a limit for connections
  73.     server.max_cons = 25 # was 256, but not needed for a LAN.
  74.     server.max_cons_per_ip = 10 # was five, but 0 is unlimited.
  75.  
  76.     # start ftp server
  77.     server.serve_forever()
  78.  
  79. if __name__ == '__main__':
  80.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement