def setUp(self): # Create a directory self.directory = self.mktemp() os.mkdir(self.directory) # Start the server p = portal.Portal(ftp.FTPRealm(self.directory)) p.registerChecker(checkers.AllowAnonymousAccess(), credentials.IAnonymous) self.factory = ftp.FTPFactory(portal=p) self.port = reactor.listenTCP(0, self.factory, interface="127.0.0.1") # Hook the server's buildProtocol to make the protocol instance # accessible to tests. buildProtocol = self.factory.buildProtocol def _rememberProtocolInstance(addr): protocol = buildProtocol(addr) self.serverProtocol = protocol.wrappedProtocol return protocol self.factory.buildProtocol = _rememberProtocolInstance # Connect a client to it portNum = self.port.getHost().port clientCreator = protocol.ClientCreator(reactor, ftp.FTPClientBasic) self.client = wait(clientCreator.connectTCP("127.0.0.1", portNum))
def main(): log.startLogging(sys.stdout) ftpDir = os.environ['FTP_DIR'] realm = ftp.FTPRealm(ftpDir, userHome=ftpDir) ftpFactory = ftp.FTPFactory() ftpFactory.portal = portal.Portal(realm) ftpFactory.portal.registerChecker( checkers.InMemoryUsernamePasswordDatabaseDontUse(admin='admin')) reactor.listenTCP(8021, ftpFactory) reactor.run()
def makeService(config): f = ftp.FTPFactory() r = ftp.FTPRealm(config["root"]) p = portal.Portal(r, config.get("credCheckers", [])) f.tld = config["root"] f.userAnonymous = config["userAnonymous"] f.portal = p f.protocol = ftp.FTP try: portno = int(config["port"]) except KeyError: portno = 2121 return internet.TCPServer(portno, f)
def makeService(config): f = ftp.FTPFactory() r = ftp.FTPRealm(config['root']) p = portal.Portal(r) p.registerChecker(checkers.AllowAnonymousAccess(), credentials.IAnonymous) if config['password-file'] is not None: p.registerChecker(checkers.FilePasswordDB(config['password-file'], cache=True)) f.tld = config['root'] f.userAnonymous = config['userAnonymous'] f.portal = p f.protocol = ftp.FTP try: portno = int(config['port']) except KeyError: portno = 2121 return internet.TCPServer(portno, f)