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