You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ftp.py 2.0KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- test-case-name: twisted.test.test_ftp_options -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """
  5. I am the support module for making a ftp server with twistd.
  6. """
  7. from twisted.application import internet
  8. from twisted.cred import portal, checkers, strcred
  9. from twisted.protocols import ftp
  10. from twisted.python import usage, deprecate, versions
  11. import warnings
  12. class Options(usage.Options, strcred.AuthOptionMixin):
  13. synopsis = """[options].
  14. WARNING: This FTP server is probably INSECURE do not use it.
  15. """
  16. optParameters = [
  17. ["port", "p", "2121", "set the port number"],
  18. ["root", "r", "/usr/local/ftp", "define the root of the ftp-site."],
  19. ["userAnonymous", "", "anonymous", "Name of the anonymous user."]
  20. ]
  21. compData = usage.Completions(
  22. optActions={"root": usage.CompleteDirs(descr="root of the ftp site")}
  23. )
  24. longdesc = ''
  25. def __init__(self, *a, **kw):
  26. usage.Options.__init__(self, *a, **kw)
  27. self.addChecker(checkers.AllowAnonymousAccess())
  28. def opt_password_file(self, filename):
  29. """
  30. Specify a file containing username:password login info for
  31. authenticated connections. (DEPRECATED; see --help-auth instead)
  32. """
  33. self['password-file'] = filename
  34. msg = deprecate.getDeprecationWarningString(
  35. self.opt_password_file, versions.Version('Twisted', 11, 1, 0))
  36. warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
  37. self.addChecker(checkers.FilePasswordDB(filename, cache=True))
  38. def makeService(config):
  39. f = ftp.FTPFactory()
  40. r = ftp.FTPRealm(config['root'])
  41. p = portal.Portal(r, config.get('credCheckers', []))
  42. f.tld = config['root']
  43. f.userAnonymous = config['userAnonymous']
  44. f.portal = p
  45. f.protocol = ftp.FTP
  46. try:
  47. portno = int(config['port'])
  48. except KeyError:
  49. portno = 2121
  50. return internet.TCPServer(portno, f)