[Twisted-Python] SSH connection, redux!

Paul Swartz z3p at twistedmatrix.com
Mon Mar 1 12:05:55 EST 2004

On Mon, 2004-03-01 at 10:25, Schollnick, Benjamin wrote:
> Folks,
> 	Thanks for the support, so far...  I downloaded the
> precompiled version of the PyCrypto and everything is working fine...
> 	Except for the fact, that I am attempting to figure out
> how to make this work the way, that I *believe* it needs to work...
> 	By the way, I was unable to get the "Writing a client with 
> Twisted.Conch" FAQ to work....  I did find the sshSimpleClient.py
> example, and that is working okay...
> 	But I am having a problem, trying to figure out how to adapt the 
> reactor model with my program...
> 	The application has, for example, 6 "ssh queries" that it needs to
> send, for example a "/usr/sbin/prtconf -v", and then "capture" the output,
> and return the output
> for processing...
> 	Then it proceeds to the next query....etc...

That's almost exactly what sshsimpleclient.py does, only it does all
three executions at once.

> 	Is there a method that I can setup the communication, and say....
> reactor.send ("asdfasdf")
> data = reactor.recv ()

You can't get data like this in Twisted, as the .recv() would block and
hang the reactor.  The dataReceived() method of the channel is called
when data is sent along that channel.

> 	More along the telnetlib design?  This way, I could branch the
> telnet code
> I use?

telnetlib is a blocking design, and doesn't work the way Twisted does. 
You might want to look into Paramiko, which (as I recall) maps fairly
closely to the telnetlib interface.

> 	Once, I start the reactor, I do not see where I can get data in and
> out,
> without using some form of a global variable...  (Or embedding the reactor
> inside
> another object)

You might want to have a look at the Writing Clients HOWTO, to get a
feel for how to write client code using the reactor.

      Paul Swartz
(o_   z3p at twistedmatrix dot com
//\   http://www.twistedmatrix.com/users/z3p.twistd/
V_/_  AIM: Z3Penguin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20040301/f67d50c1/attachment.pgp 

More information about the Twisted-Python mailing list