Hello. I'm writing a Python program that connects to servers through
telnetlib to execute a few commands. The code is as follows:
import sys,telnetlib,re,string,csv,time,os
def Telnet():
HOST="192.168.51.50"
USER = "emsadmin"
PASSWORD = "emsadmin"
telnet = telnetlib.Telnet(HOST)
telnet.read_until("login as: ")
telnet.write("USER \n\r")
telnet.read_until("Password: ")
telnet.write("PASSWORD \n\r")
print telnet.read_all()
I've discovered that some of the servers that I have to connect to with this program run only SSH, so I need to add support for SSH to the program. I'm looking for a library that behaves similarly to telnetlib for SSH connections.
I came to know that plink from the putty website works for this.
But i am not clear with the code.
Please check this and let me know how to pass the commands to it similar to the above code...
import sys,telnetlib,re,string,csv,time,os
def Telnet():
HOST="192.168.51.50"
USER = "emsadmin"
PASSWORD = "emsadmin"
os.system("cls")
plink = os.system("c:\Python\Lib\plink.exe 192.168.51.50")
.....
Upto here it is working and connecting to the ssh session. But after that i am not able to know about how to pass the username and password.
Any help is appreciated.