-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh.py
30 lines (25 loc) · 774 Bytes
/
ssh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import paramiko
hostname = "hostname"
port = 22
username = "username"
password = "password"
command = "ls /home"
try :
client=paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname = hostname, port = port, username= username, password = password)
print ("\nSSH connection to %s established.\n\n" %hostname)
hasil = ""
stdin, stdout, stderr = client.exec_command(command)
except paramiko.SSHException as sshException:
print ("\n%s\n\n" %sshException)
result_flag = False
stdout=stdout.readlines()
for line in stdout:
hasil = hasil + line
if hasil != "":
print (hasil)
else:
print ("There was no result for this command")
client.close()
print ("\n\nLogged out\nConnection to %s closed.\n" %hostname)