Not sure what you mean, but here is a basic example:

from zope.interface import implements

from twisted.application import service, internet
from twisted.conch.ssh.keys import Key
from twisted.conch.ssh.factory import SSHFactory
from twisted.conch.unix import UnixSSHRealm
from twisted.cred.checkers import ICredentialsChecker
from twisted.cred.credentials import IUsernamePassword
from twisted.cred.portal import Portal


def get_key(path):
    return Key.fromString(data=open(path).read())


class DummyChecker(object):
    credentialInterfaces = (IUsernamePassword,)
    implements(ICredentialsChecker)

    def requestAvatarId(self, credentials):
        return credentials.username


def makeService():
    public_key = get_key('id_rsa.pub')
    private_key = get_key('id_rsa')

    factory = SSHFactory()
    factory.privateKeys = {'ssh-rsa': private_key}
    factory.publicKeys = {'ssh-rsa': public_key}
    factory.portal = Portal(UnixSSHRealm())
    factory.portal.registerChecker(DummyChecker())

    return internet.TCPServer(2200, factory)


application = service.Application("sftp server")
sftp_server = makeService()
sftp_server.setServiceParent(application)


Put this content into a file like sftp.tac
The keys can be generated by ckeygen utility which is part of Twisted
(e.g. ckeygen -b 2048 -t rsa -f id_rsa)
and run with twistd -ny sftp.tac

If you want more background on Twisted conch i suggest the "Twisted Conch in
60 Seconds" series by
Jean-Paul Calderone on his blog http://as.ynchrono.us/

Michal Mach


On Mon, Aug 22, 2011 at 10:31 PM, Osborn Chan <[email protected]> wrote:

> Yes. It is SFTP, and I found that filetransfer.FileTransferServer is a
> subsystem under UnixConchUser.
>
>        self.subsystemLookup.update({"sftp":
> filetransfer.FileTransferServer})
>
> However, I was able to start a ssh shell by using SSHFactory and
> UnixSSHReam, but I was not able to start SFTP as sub system.
>
> Do I need to do anything explicitly to start sftp subsystem?
>
> Thanks,
>
> -Osborn
> newbie in Python and Twisted.
>
>
> On 8/22/11 12:50 PM, "Jasper St. Pierre" <[email protected]> wrote:
>
> >What about twisted.conch.ssh.filetransfer? Is that not SFTP?
> >
> >On Mon, Aug 22, 2011 at 3:36 PM, Drew Smathers <[email protected]>
> >wrote:
> >> On Fri, Aug 19, 2011 at 2:43 PM, Osborn Chan <[email protected]> wrote:
> >>> Hi,
> >>>
> >>> I am a newbie in twisted and python.
> >>> I would like to create a python SFTP server with twisted, but I cannot
> >>>find any sample.
> >>>
> >>> Can someone give me some advise?
> >>>
> >>
> >> I don't believe there are any examples of building an SFTP server
> >> aimed at newcomers to twisted and python but there are existing
> >> implementations in the wild--which might honestly be difficult to
> >> digest if you don't know python well enough. I think zope at one time
> >> has SFTP server based on twisted (which I can't seem to summon with
> >> google) and there's also SFTP server implementation in tahoe-lafs
> >>
> >>(
> https://github.com/warner/tahoe-lafs/blob/master/src/allmydata/frontends
> >>/sftpd.py).
> >>
> >> -Drew
> >>
> >> _______________________________________________
> >> Twisted-Python mailing list
> >> [email protected]
> >> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> >>
> >
> >
> >
> >--
> >  Jasper
> >
> >_______________________________________________
> >Twisted-Python mailing list
> >[email protected]
> >http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>
> _______________________________________________
> Twisted-Python mailing list
> [email protected]
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
_______________________________________________
Twisted-Python mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to