[Twisted-Python] dynamic FTP realm
Paul Wiseman
poalman at gmail.com
Sat Sep 29 13:44:51 MDT 2012
On 28 September 2012 15:32, Tom Sheffler <tom.sheffler at gmail.com> wrote:
> 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.
> """
> implements(portal.IRealm)
>
> def __init__(self, ....)
> ....
>
> def requestAvatar(self, avatarId, mind, *interfaces):
> for iface in interfaces:
> if iface is IFTPShell:
> if avatarId is checkers.ANONYMOUS:
> avatar = None
> else:
> avatar = PaulsFTPShell( ...)
>
> return IFTPShell, avatar, getattr(avatar, 'logout',
> lambda: None)
> 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)
> p.registerChecker(...)
>
> f.portal = p
>
> Hope this helps get you started.
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>
Thank you. I've made quite a bit of progress and now have my own Portal,
CredentialsChecker, Realm, Shell, and FilePath object.
One thing I haven't been able to work out is, when I override, lets say
listdir for example in FilePath, I need to make a webcall to find out the
folder contents, how can I make this call asynchronously?
I'm guessing I need to used deferred in someway, but seeing as listdir
doesn't return deferred objects I'm not sure how to make it work.
As listdir gets called from the Shell I guess I could change how blocking
calls in my FilePath object get called?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20120929/85b0bdeb/attachment.html>
More information about the Twisted-Python
mailing list