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 __init__(self, client, accountfile, accounturl, ftp_portstr): service.MultiService.__init__(self) # make sure we're using a patched Twisted that uses IWriteFile.close: # see docs/frontends/FTP-and-SFTP.txt and # http://twistedmatrix.com/trac/ticket/3462 for details. if "close" not in ftp.IWriteFile.names(): raise AssertionError( "your twisted is lacking a vital patch, see docs/frontends/FTP-and-SFTP.txt" ) r = Dispatcher(client) p = portal.Portal(r) if accountfile: c = AccountFileChecker(self, accountfile) p.registerChecker(c) if accounturl: c = AccountURLChecker(self, accounturl) p.registerChecker(c) if not accountfile and not accounturl: # we could leave this anonymous, with just the /uri/CAP form raise NeedRootcapLookupScheme("must provide some translation") f = ftp.FTPFactory(p) s = strports.service(ftp_portstr, f) s.setServiceParent(self)
def __init__(self, port): realm = FTPRealm(get_poppy_root()) portal = Portal(realm) portal.registerChecker(PoppyAccessCheck()) factory = ftp.FTPFactory(portal) factory.tld = get_poppy_root() factory.protocol = ftp.FTP factory.welcomeMessage = "Launchpad upload server" factory.timeOut = config.poppy.idle_timeout self.ftpfactory = factory self.portno = port
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 getPorts(app, config): t = ftp.FTPFactory() # setting the config t.anonymous = config.anonymous t.thirdparty = config.thirdparty t.root = config.root t.useranonymous = config.useranonymous t.otp = config.otp t.userdict = {} # adding a default user addUser(t, "twisted", "twisted") try: portno = config.portno except AttributeError: portno = 2121 return [(portno, t)]
def __init__(self, client, accountfile, accounturl, ftp_portstr): service.MultiService.__init__(self) r = Dispatcher(client) p = portal.Portal(r) if accountfile: c = AccountFileChecker(self, accountfile) p.registerChecker(c) if accounturl: c = AccountURLChecker(self, accounturl) p.registerChecker(c) if not accountfile and not accounturl: # we could leave this anonymous, with just the /uri/CAP form raise NeedRootcapLookupScheme("must provide some translation") f = ftp.FTPFactory(p) s = strports.service(ftp_portstr, f) s.setServiceParent(self)
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)
def __init__(self, client, accountfile, accounturl, ftp_portstr): precondition(isinstance(accountfile, (unicode, NoneType)), accountfile) service.MultiService.__init__(self) r = Dispatcher(client) p = portal.Portal(r) if accountfile: c = AccountFileChecker(self, accountfile) p.registerChecker(c) if accounturl: c = AccountURLChecker(self, accounturl) p.registerChecker(c) if not accountfile and not accounturl: # we could leave this anonymous, with just the /uri/CAP form raise NeedRootcapLookupScheme("must provide some translation") f = ftp.FTPFactory(p) # strports requires a native string. ftp_portstr = ensure_str(ftp_portstr) s = strports.service(ftp_portstr, f) s.setServiceParent(self)
class FTPRealm: implements(portal.IRealm) def __init__(self, anonymousRoot): self.anonymousRoot = filepath.FilePath(anonymousRoot) self.dir = {'ljd': "/tmp", 'root': '/'} def requestAvatar(self, avatarId, mind, *interfaces): for iface in interfaces: if iface is ftp.IFTPShell: if avatarId is checkers.ANONYMOUS: avatar = ftp.FTPAnonymousShell(self.anonymousRoot) else: user_dir = self.dir[avatarId] avatar = ftp.FTPShell(filepath.FilePath(user_dir)) return ftp.IFTPShell, avatar, getattr(avatar, 'logout', lambda: None) raise NotImplementedError( "Only IFTPShell interface is supported by this realm") portal = portal.Portal(FTPRealm('/data')) portal.registerChecker(checkers.AllowAnonymousAccess()) portal.registerChecker(checkers.FilePasswordDB("pwd.txt")) f = ftp.FTPFactory(portal) from twisted.internet import reactor reactor.listenTCP(1234, f) reactor.run()