[Twisted-Python] Conch channel blocked

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Thu Feb 4 09:01:57 EST 2010

On 2 Feb, 09:24 pm, jbardin at bu.edu wrote:
>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 >
>                                  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

I can't run your example code, since it's not a complete example.  That 
makes it harder to point out what's wrong with it.  However, one thing 
does strike me as wrong:
>        while chunk:
>            self.write(chunk)
>            chunk = f.read(4096)

This is a pattern you typically want to avoid, in Conch or anything else 
Twisted-based.  I don't know if SSHChannel is a consumer, but if not it 
should be, and you should be writing the file using a producer.  See:

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

Mantissa uses Twisted Conch a bit:


But you won't find any code sending any exec requests there.


More information about the Twisted-Python mailing list