467,864 Members | 1,784 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,864 developers. It's quick & easy.

SSH using Paramiko

Hello,

I'm using paramiko 0.9 to access one of my home machines and then execute
a command. But with the script included below, the command gets executed
on the 2nd to 6th go, never on the first. And the commands aren't that
commplicated, they are usualy 'touch some-file' or
'cp some_file to /tmp/a'.

Am I misunderstanding the paramiko's API or ... ?

This is the script:

import sys
import socket
import traceback
import threading
import paramiko
hostname = "192.168.0.10"
username = "alex"
port = 22
password = 'asdfg6'

# now connect
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((hostname, port))
except Exception, e:
print 'Connect failed: ' + str(e)
traceback.print_exc()
sys.exit(1)

t = paramiko.Transport(sock)
event = threading.Event()
t.start_client(event)
print "started client"
event.wait(15)

if not t.is_active():
print 'SSH negotiation failed.'
sys.exit(1)
else:
print "SSH negotiation sucessful"

print "doing authentication"
t.auth_password(username, password, event)
event.clear()
event.wait(20)

if not t.is_authenticated():
print 'Authentication failed. :('
t.close()
sys.exit(1)

if not t.is_active():
print "Channel is not active"
else:
print "Channel is active"
chan = t.open_session()
print "session opened"
print "Channel name is " + chan.get_name()
chan.exec_command("cp /etc/ftpusers /tmp/")
print "executing the command"
chan.close()
t.close()
print "exiting"

Thanks

P.S. I'm aware that this is not one of the cleanest scripts out there.
Or even very security conscious. All I'm looking for is to get it to work,
then I'll worry about it after.

Jul 18 '05 #1
  • viewed: 1749
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by eight02645999 | last post: by
reply views Thread by washakie | last post: by
1 post views Thread by Terry Reedy | last post: by
1 post views Thread by sa6113 | last post: by
4 posts views Thread by sa6113 | last post: by
reply views Thread by sa6113 | last post: by
reply views Thread by sa6113 | last post: by
reply views Thread by sa6113 | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.