[Twisted-Python] Conch channel blocked

james bardin jbardin at bu.edu
Tue Feb 2 16:24:08 EST 2010


Hello,

I'm trying to get a feel for twisted.conch, and not getting very far.
I know the documentation is lacking, but I'm not here to complain, I'm
here to figure this out. I only have a cursory knowledge of twisted so
far, so that may be some of my problem. I am however fairly familiar
with the internals of ssh, so I thought I could start there...

I started with the sshsimpleclient example, took some pieces, and
began experimenting.
The example worked as expected.
Next, I wanted to pipe arbitrary data over the channel, as if I called
"ssh hostname 'cat > file'"
This however fills the remote buffer, and hangs

Here's a small example
###############
class ClientConnection(connection.SSHConnection):
    def serviceStarted(self):
        self.openChannel(CatChannel(conn = self))

class CatChannel(channel.SSHChannel):
    name = 'session'
    def channelOpen(self, data):
        d = self.conn.sendRequest(self, 'exec', common.NS('cat >
/tmp/testfile'),
                                  wantReply = 1)
        d.addCallback(self._cbSendRequest)

    def _cbSendRequest(self, ignored):
        f = open('testfile')
        chunk = f.read(4096)
        while chunk:
            self.write(chunk)
            chunk = f.read(4096)
        f.close()
        self.conn.sendEOF(self)
        self.loseConnection()
################


Also, setting the channel name to 'session', sending the 'exec'
request with the command as a netstring, etc. seem like something that
should be abstracted away. SSHSession with request_exec seemed like
the obvious choice, but I had no success in using that class for
anything.

Does anyone know if any projects making good use of twisted.conch,
where I can see the source in action, and in depth?


Thanks,
-jim



More information about the Twisted-Python mailing list