473,289 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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
0 2051

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: eight02645999 | last post by:
hi i downloaded paramiko and was trying to create private/pub key pairs from the docs, i use this method to create private key import paramiko k = paramiko.RSAKey.generate(1024)...
0
by: washakie | last post by:
Hello, I'm trying to write a script which will allow me to initiate (spawn?) an SSH reverse tunnel from an internal box (inside a firewall) to an external box, while logged into the external box. ...
1
by: Terry Reedy | last post by:
"Praveena B" <praveena_python@yahoo.comwrote in message news:808793.504.qm@web44809.mail.sp1.yahoo.com... when i used paramiko in python2.5 i got the error below. File "C:\praveena\python...
1
by: sa6113 | last post by:
I use this code : import paramiko import socket hostname = "192.168.1.4" username = "test" port = 22 password = ''123456"
4
by: sa6113 | last post by:
I couldn't find any good source for download Openssh on the net? Would you please introduce a URL for download that? Steve Holden-5 wrote: -- View this message in context:...
0
by: sa6113 | last post by:
I am using this code to connect to a windows machine using paramiko, I have installed sshd on the machine and it works properly: sock.connect((hostname, port)) t = paramiko.Transport(sock)...
0
by: sa6113 | last post by:
which program I have to install for using paramiko for sftp between a two windows machine in local network?? I have installed freeSSHd for server machine but I got an Authentication failed erro...
0
by: sa6113 | last post by:
I want to connect to a Windows machine in my network , using ssh, I use paramiko but I have problem in authentication, would you please help me? 1- I have installed freeSSHD in server machine? Is...
0
by: sa6113 | last post by:
I want to connect to a Windows machine in my network , using ssh, I use paramiko but I have problem in authentication, would you please help me? 1- I have installed freeSSHD in server machine? Is...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.