[Twisted-Python] Running commands (ssh) from a GUI client

Raúl Gómez C. nachogomez at gmail.com
Tue Oct 9 15:21:54 EDT 2007

Thank you very much Paul, I'll give it a try and I'll post any change, I'm
really grateful... but giving it an overview, I think you are not executing
the commands the way I want, when you pass a list of commands on the
Dashboard (self.run_commands("myhost", "myusername", "mypassword", ["id",
"pwd", "ls -l"])) you are running it asynchronously (the way I'm getting it,
I mean, the three commands are passed to the CommandChannel class, and then
they gets run, and later they return it's data), I need to run commands from
the GUI, without previously knowing what commands will the user want to run
(the normal GUI interaction), and avoiding to all cost to authenticate for
each command (that's because some networks that my tool will connect takes
too long to authenticate ssh connections, but once they are authenticated,
they works just fine).

But thanks again Paul, if you want a suggestion on your code, I think (but
I'm not sure) you can get rid of a lot of code if you implement something
like I have (see below, in the answer to Jean-Paul), if you iterate on the
list of command, you can change the raw_input() with something like this:

for cmd in self.cmds:
    self.requestService(PasswordAuth(self.username, self.password,

Just a suggestion, hope that helps...

On 10/9/07, Paul_S_Johnson at mnb.uscourts.gov <Paul_S_Johnson at mnb.uscourts.gov>
> Raul,
> This is simply some work-in-progress code, but is basically what you are
> looking for even written for PythonCard. This takes a list of three commands
> and runs them in the order given using deferreds to wait for the previous to
> complete before executing the next.
> This took me about forever to get it this far. If you make and significant
> improvements, please share.
> One remaining mystery is how to switch users once logged in. For example,
> I need to run some things as root.
> Paul

Jean-Paul, is not easy to post only a small working (by itself) part of what
I'm trying to do, is the sshclient.py (example
10-4)<http://www.ora.de/catalog/twistedadn/chapter/ch10.pdf>of the
Network Programming Essentials Book by Abe Fettig (based on the
sshsimpleclient.py by Paul Swartz), but modified in order ask for the
command when the ClientConnection class is called in the
ClientCommandTransport class, like this:

class ClientCommandTransport(transport.SSHClientTransport):

    def __init__(self, username, password):
        self.username = username
        self.password = password

    def verifyHostKey(self, pubKey, fingerprint):
        # in a real app, you should verify that the fingerprint matches
        # the one you expected to get from this server
        return defer.succeed(True)

    def connectionSecure(self):
        cmd= ''
        while True:
            cmd = raw_input('Command: ')
            if cmd != 'quit':
self.password, ClientConnection(cmd)))
                print '\nGood Bye!\n'

Note: the Bold part is what I've added to the original code

PD: I think Paul is a popular name in this list :p
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20071009/b7ec8cce/attachment.htm 

More information about the Twisted-Python mailing list