473,842 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 misunderstandin g 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(s ocket.AF_INET, socket.SOCK_STR EAM)
sock.connect((h ostname, port))
except Exception, e:
print 'Connect failed: ' + str(e)
traceback.print _exc()
sys.exit(1)

t = paramiko.Transp ort(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_authentica ted():
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_comma nd("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 2076

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

Similar topics

2
5173
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) k.write_private_key_file("test_priv") How do i generate the public key for this ? thanks
0
1173
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. I posted to another list and was pointed in the direction of paramiko. I've read the tutorials, but cannot seem to figure out exactly how I can do this... I'm hoping someone can look at what I'm trying to do below and provide an example... ...
1
2413
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 scripts\sshlib\ssh.py", line 5, in <module> import paramiko File "C:\Python25\Lib\site-packages\paramiko\__init__.py", line 69, in <module> from transport import randpool, SecurityOptions, Transport File...
1
3869
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
2713
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: http://www.nabble.com/ssh-problem-using-paramiko--tp19857268p19875248.html Sent from the Python - python-list mailing list archive at Nabble.com.
0
2205
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) event = threading.Event() t.start_client(event) event.wait() if not t.is_active(): print 'SSH negotiation failed.'
0
1515
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 when try to connect to server using this code : sock.connect((hostname, port)) t = paramiko.Transport(sock) event = threading.Event() t.start_client(event)
0
1380
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 it necessery ? or may I have to install another program? 2- I have entered server's Ip insted of hostname.Is it correct? 3- I have creat a user in server machine with a password to connect. Am I right?
0
2547
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 it necessery ? or may I have to install another program? 2- I have entered server's Ip insted of hostname.Is it correct? 3- I have creat a user in server machine with a password to connect. Am I right? 4- I use this code in clinet...
0
9875
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10945
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10614
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7859
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7040
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5697
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5886
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4500
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3146
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.