1

this is my code:

import paramiko
import time

host = "123.456.789"
username = "myusername"
password = "mypassword"

client = paramiko.client.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, username=username, password=password)
_stdin, _stdout,_stderr = client.exec_command("sudo -i")
_stdin.write(password + '\n')
_stdin, _stdout,_stderr = client.exec_command("sudo wget -O- 'https://abc.com.gz' | gunzip | dd of=/dev/sda", get_pty=True)
_stdin.flush()
#Print content
for line in _stdout.readlines():
   print(_stdout.read().decode())
# Close ssh connect
time.sleep(5)
client.close()

the result I get is the screen doesn't print anything, and after a period of ~30-40 minutes the server doesn't receive any files from the wget command....

Philip
  • 69
  • 6

1 Answers1

0

Try to invoke the Shell instead:

import paramiko, time

host = "123.456.789"
username = "myusername"
password = "mypassword"
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, username=username, password=password)
remote_shell = client.invoke_shell()

remote_shell.send("sudo -i")
remote_shell.send(password + "\n")
remote_shell.send("sudo wget -O- 'https://abc.com.gz' | gunzip | dd of=/dev/sda")

# print reply
time.sleep(1)
print(remote_shell.recv(65535))
time.sleep(1)
client.close()
Cow
  • 2,543
  • 4
  • 13
  • 25
  • this is code working, thank you: remote_shell.send("sudo -i" + "\n") remote_shell.send(password + "\n") time.sleep(2) remote_shell.send("wget -O- 'abc.com' | gunzip | dd of=/dev/sda" + "\n") – Philip Aug 19 '22 at 10:34