[Twisted-Python] Implementing a custom FTP server

Andy Gayton andy at thecablelounge.com
Mon Sep 6 21:35:34 EDT 2004


>> On Mon, 2004-09-06 at 14:34 -0500, Jason Stitt wrote:
>>To answer your further questions, I'm not that experienced with 
>>programming the FTP or SFTP protocol (yet...) so I don't know a lot 
>>about the differences. I want to use SFTP eventually for security 
>>reasons but figured that FTP would be simpler to start out with. If 
>>they're that different, perhaps I should start looking into SFTP from 
>>the start.


Paul Swartz wrote:
> It's easier to talk about the similarities between SFTP and FTP than the
> differences.  The only real similarities between the two protocols are
> 1) the names 2) that they interface to a filesystem.  Other than that,
> they're two entirely different protocols.  The Interfaces that Conch's
> SFTP implementation uses are twisted.conch.interfaces.ISFTPServer and
> ISFTPFile.

G'dday Jason,

I'm chipping away in this area as well as I find time.  I started with 
SFTP - but also want to support all filelike interfaces in the future.

I've opened up svn access to what I have so far:

svn list svn://twisted.cablelounge.com/welsh/trunk

Its very rough .. pretty embarrassing really :) .. hopefully its of some 
help though, and it'd be good to get feedback - particularly as you're 
working with FTP.

The general strategy is to represent your file store independent of any 
protocol.  I've a simple sambaish like file store in file.py.  Then for 
each protocol write an adaptor from your file store objects to the 
interface that protocols expects.  fileadapt.py does this for SFTP. 
realm.py ties it all together.

You can play with it by creating a tap file:

mktap welsh -p 5822 -d /etc/ssh

or something similiar - it's pretty much conch ..

Then create a file 'welshpasswd' to define the accounts on your system 
and place it in the same directory as the tap file.

The file sets up a users variable:

users = {
     loginuserid : {
         nameOfVirtualDirectory  : (uid, gid, realSystemDirectory),
         nameOfVirtualDirectory2 : (uid, gid, realSystemDirectory2),
     }
}

example welshpasswd:
---------------------
users = {
     "andy" : {
             "home"   : ( 509, 509, "/home/andy" ),
     },
     "az" : {
             "home"              : ( 518, 518, "/home/az/incoming" ),
             "giiwa"             : ( 108, 108, "/home/giiwa" ),
             "muddypigrecords"   : (  99,  99, "/home/muddypigrecords" ),
     },
}
----------------------

erg, apologies for the roughness :(

When az logins in, he'll see three directories, home, giiwa and 
muddypigrecords - while working in those directories he'll assume the 
uid and gid and be working in the physical directory as defined above.

 > Itamar Shtull-Trauring wrote:
> 1. Twisted's FTP server has in theory support for generic backends?
> (though it is currently being rewritten, so you could help with that).

Good luck!  I'm yet to take a look, but wouldn't mind helping out if the 
FTP backend needs a bit of work to be made more accessible.

Andy.













More information about the Twisted-Python mailing list