| OLD | NEW |
| (Empty) |
| 1 | |
| 2 # Copyright (c) 2001-2004 Twisted Matrix Laboratories. | |
| 3 # See LICENSE for details. | |
| 4 | |
| 5 | |
| 6 """ | |
| 7 I am the support module for making a ftp server with mktap. | |
| 8 """ | |
| 9 | |
| 10 from twisted.protocols import ftp | |
| 11 from twisted.python import usage | |
| 12 from twisted.application import internet | |
| 13 from twisted.cred import error, portal, checkers, credentials | |
| 14 | |
| 15 import os.path | |
| 16 | |
| 17 | |
| 18 class Options(usage.Options): | |
| 19 synopsis = """Usage: mktap ftp [options]. | |
| 20 WARNING: This FTP server is probably INSECURE do not use it. | |
| 21 """ | |
| 22 optParameters = [ | |
| 23 ["port", "p", "2121", "set the port number"], | |
| 24 ["root", "r", "/usr/local/ftp", "define the root of the ftp-site."
], | |
| 25 ["userAnonymous", "", "anonymous", "Name of the anonymous user."], | |
| 26 ["password-file", "", None, "username:password-style credentia
ls database"], | |
| 27 ] | |
| 28 | |
| 29 longdesc = '' | |
| 30 | |
| 31 | |
| 32 def makeService(config): | |
| 33 f = ftp.FTPFactory() | |
| 34 | |
| 35 r = ftp.FTPRealm(config['root']) | |
| 36 p = portal.Portal(r) | |
| 37 p.registerChecker(checkers.AllowAnonymousAccess(), credentials.IAnonymous) | |
| 38 | |
| 39 if config['password-file'] is not None: | |
| 40 p.registerChecker(checkers.FilePasswordDB(config['password-file'], cache
=True)) | |
| 41 | |
| 42 f.tld = config['root'] | |
| 43 f.userAnonymous = config['userAnonymous'] | |
| 44 f.portal = p | |
| 45 f.protocol = ftp.FTP | |
| 46 | |
| 47 try: | |
| 48 portno = int(config['port']) | |
| 49 except KeyError: | |
| 50 portno = 2121 | |
| 51 return internet.TCPServer(portno, f) | |
| OLD | NEW |