Guest User

Untitled

a guest
Oct 5th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. import paramiko
  2. import sys
  3. import os
  4. import subprocess
  5. import time
  6. import datetime
  7. import cmd
  8.  
  9. now = datetime.datetime.now()
  10. buff = ''
  11. resp = ''
  12. ini_path = '/home/rajesh/python/Imagecopy'
  13. os.makedirs(ini_path)
  14.  
  15. with open('imagecopt.txt') as f:
  16. for line in f:
  17. line = line.strip()
  18. try:
  19. line = line.strip()
  20. dssh = paramiko.SSHClient()
  21. dssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  22. dssh.connect(line, username='*****',password='&&&&&&')
  23. chan = dssh.invoke_shell()
  24. output = chan.recv(1000)
  25. print output
  26. print"SSH connection established to %s" % line
  27. sftp = dssh.open_sftp()
  28. sftp.put('/home/rajesh/python/test.txt','Flash:')
  29. sftp.close()
  30. #resp = chan.recv(9999)
  31. print line, "Reachable ~ Command Executed"
  32. dssh.close()
  33. fin_path = os.path.join(ini_path, line)
  34. fp=open(fin_path + '.txt',"w")
  35. fp.write(resp)
  36.  
  37. fp.close()
  38.  
  39.  
  40. except Exception as e:
  41. print line, "ERROR: ", e
Add Comment
Please, Sign In to add comment