[paramiko] migrate from Telnet to SSH
James Bardin
jbardin at bu.edu
Fri Jul 13 08:22:56 PDT 2007
Chris Hallman wrote:
> Is channel the same a TCP connection?
>
> I've looked around can't find any example similar to what I need nor
> can I
> figure out from the documentation what I need to do. I know that
> client below
> instantiates the object/class. It opens the TCP connection. I just don't
> want to be creating thousands of TCP connections if I can get away with
> re-using the existing one. I've no idea yet how to do what I need. If you
> have any suggestions, I'd be grateful.
>
You're going to have to go beneath the SSHClient class, and use the
building blocks yourself.
The pydocs are very good if you haven't seen them -
http://www.lag.net/paramiko/docs/
This is what I would try next. You can do this interactively in the
python shell, idle, ipython, etc.
######
import socket
import paramiko
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((''rtr3926', 22))
trans = paramiko.Transport(sock)
trans.auth_password('user', 'password')
# now open a channel that we're not going to use
dummy_chan = trans.open_session()
# here's the exec_command function from SSHClient
def exec_command(command):
chan = trans.open_session()
chan.exec_command(command)
stdin = chan.makefile('wb')
stdout = chan.makefile('rb')
stderr = chan.makefile_stderr('rb')
return stdin, stdout, stderr
stdin, stdout, stderr = exec_commnd('command')
########...
Hopefully the dummy_chan being left open will prevent the server from
trying to close the connection.
-jim
--
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
James Bardin - Systems Analyst / Administrator I
Boston University Department of Electrical and Computer Engineering
8 Saint Mary's St, Room 305, Boston, MA 02215
Ph:617-358-2785 http://www.bu.edu/ece/it
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
More information about the paramiko
mailing list