Guest User

Untitled

a guest
Feb 15th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import time
  2. import paramiko
  3. import os
  4. import getpass
  5.  
  6.  
  7. output=''
  8.  
  9. host='192.168.0.106'
  10. user=input('enter username:')
  11. psw = getpass.getpass()
  12. try:
  13. ssh = paramiko.SSHClient()
  14. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  15. ssh.connect(host, username=user, password=psw, port=22)
  16. except:
  17. print('login failed')
  18. exit()
  19. print(host+' login success')
  20. try:
  21. channel = ssh.invoke_shell()
  22. except:
  23. print(q+' unknown device type')
  24. a=input('press enter to exit:')
  25. exit()
  26. time.sleep(4)
  27. channel.send('cd Documents \n')
  28. time.sleep(1)
  29. channel.send('cat Hi.txt \n')
  30. time.sleep(1)
  31. while channel.recv_ready():
  32. device_type=''
  33. #time.sleep(0.5)
  34. out = channel.recv(99999999)
  35. device_type=out.decode("ascii")
  36. output+=device_type
  37. print(output)
  38. #if output.endswith('pi@raspberrypi:~/Documents$'):break
  39. f=open('output.txt','w+')
  40. f.writelines(output)
  41. #print (len(output))
Add Comment
Please, Sign In to add comment