[Twisted-Python] dynamic FTP realm

Tom Sheffler tom.sheffler at gmail.com
Fri Sep 28 10:32:43 EDT 2012

Hi Paul -

I'm very new to twisted (I've only just started using it, so I apologise if
> anything I ask is seemingly obvious!).
> I'm looking to try and set up a FTP server which will serve a file
> structure and files which don't exists on the server (the file structure
> information is stored on cassandra, and the files are on s3). The file
> structure and files will also be unique to the user, so different logins
> will generate the file structure for that particular user, but I guess I
> can adress that later.

Here is a quick sketch of some of the steps ... but beware, I haven't
debugged this.  You'll want to subclass twisted.protocols.ftp.FTPShell with
a new command interpreter

    class PaulsFTPShell(FTPShell):

The you'll need to write a Realm that returns an instance of your FTP Shell:

class PaulsFTPRealm(FTPRealm):
    @type anonymousRoot: L{twisted.python.filepath.FilePath}
    @ivar anonymousRoot: Root of the filesystem to which anonymous
    users will be granted access.

    def __init__(self, ....)

    def requestAvatar(self, avatarId, mind, *interfaces):
        for iface in interfaces:
            if iface is IFTPShell:
                if avatarId is checkers.ANONYMOUS:
                    avatar = None
                    avatar = PaulsFTPShell( ...)

                return IFTPShell, avatar, getattr(avatar, 'logout', lambda:
        raise NotImplementedError("Only IFTPShell interface is supported by
this realm")

Then you'll stich it all together like this:

    f = FTPFactory()
    r = PaulsFTPRealm()
    p = Portal.Portal(r)

    f.portal = p

Hope this helps get you started.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20120928/99670c1b/attachment.htm 

More information about the Twisted-Python mailing list