Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from paramiko import client
- class ssh:
- client = None
- def __init__ (self, server_addr,username, password, keyfile):
- print ("Establishing VM connection")
- #Create ssh client.
- self.client = client.SSHClient ()
- ## The following line is required if you want the script to be able to access a server that's not yet in the known_hosts.
- self.client.set_missing_host_key_policy (client.AutoAddPolicy())
- #Make the connection.
- self.client.connect (server_addr, username=username, password=password, key_filename=keyfile);
- def sendCommand (self, command):
- #Check if connection is made successfully.
- if (self.client) :
- stdin,stdout,stderr = self.client.exec_command (command)
- while not stdout.channel.exit_status_ready ():
- alldata = stdout.channel.recv (1024)
- while stdout.channel.recv_ready ():
- alldata += stdout.channel.recv(1024)
- print (str(alldata))
- else:
- print "Connection is not opened"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement