On 28 September 2012 15:32, Tom Sheffler <span dir="ltr"><<a href="mailto:tom.sheffler@gmail.com" target="_blank">tom.sheffler@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Paul -<div class="im"><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">I'm very new to twisted (I've only just started using it, so I apologise if<br></span><span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">anything I ask is seemingly obvious!).</span><br style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">I'm looking to try and set up a FTP server which will serve a file<br></span><span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">structure and files which don't exists on the server (the file structure<br>
</span><span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">information is stored on cassandra, and the files are on s3). The file<br></span><span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">structure and files will also be unique to the user, so different logins<br>
</span><span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">will generate the file structure for that particular user, but I guess I<br></span><span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">can adress that later.</span></blockquote>
</blockquote><div><span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><br></span></div><div><br></div></div><div><font color="#222222" face="arial, sans-serif">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</font></div>
<div><font color="#222222" face="arial, sans-serif"><br></font></div><div><font color="#222222" face="arial, sans-serif"> class PaulsFTPShell(FTPShell):</font></div><div><font color="#222222" face="arial, sans-serif"> ....</font></div>
<div><font color="#222222" face="arial, sans-serif"><br></font></div><div><font color="#222222" face="arial, sans-serif">The you'll need to write a Realm that returns an instance of your FTP Shell:</font></div><div><font color="#222222" face="arial, sans-serif"><br>
</font></div><div><font color="#222222" face="arial, sans-serif"><div>class PaulsFTPRealm(FTPRealm):</div><div> """</div><div> @type anonymousRoot: L{twisted.python.filepath.FilePath}</div><div> @ivar anonymousRoot: Root of the filesystem to which anonymous</div>
<div> users will be granted access.</div><div> """</div><div> implements(portal.IRealm)</div><div><br></div><div> def __init__(self, ....)</div><div> ....</div><div><br></div><div> def requestAvatar(self, avatarId, mind, *interfaces):</div>
<div> for iface in interfaces:</div><div> if iface is IFTPShell:</div><div> if avatarId is checkers.ANONYMOUS:</div><div> avatar = None</div><div> else:</div>
<div> avatar = PaulsFTPShell( ...)</div><div><br></div><div> return IFTPShell, avatar, getattr(avatar, 'logout', lambda: None)</div><div> raise NotImplementedError("Only IFTPShell interface is supported by this realm")</div>
<div><br></div></font></div><div><br></div><div>Then you'll stich it all together like this:</div><div><br></div><div><br></div><div><font color="#222222" face="arial, sans-serif"> f = FTPFactory()</font></div><div>
<font color="#222222" face="arial, sans-serif"> r = PaulsFTPRealm()</font></div>
<div><font color="#222222" face="arial, sans-serif"> p = Portal.Portal(r)</font></div><div><font color="#222222" face="arial, sans-serif"> p.registerChecker(...)</font></div><div><font color="#222222" face="arial, sans-serif"><br>
</font></div><div><font color="#222222" face="arial, sans-serif"> f.portal = p</font></div><div><br></div><div><font color="#222222" face="arial, sans-serif">Hope this helps get you started.</font></div><div><font color="#222222" face="arial, sans-serif"><br>
</font></div>
<br>_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
<br></blockquote></div><br><div><br></div><div>Thank you. I've made quite a bit of progress and now have my own Portal, CredentialsChecker, Realm, Shell, and FilePath object.</div><div><br></div><div>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?</div>
<div><br></div><div>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.</div><div><br></div><div>As listdir gets called from the Shell I guess I could change how blocking calls in my FilePath object get called?</div>