Advertisement
Guest User

Untitled

a guest
Aug 28th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import paramiko
  2. import time
  3. import os
  4.  
  5.  
  6. def touch(path):
  7. with open(path, 'a'):
  8. os.utime(path, None)
  9.  
  10.  
  11. ssh = paramiko.SSHClient()
  12.  
  13. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  14.  
  15. ssh.connect('ip', port=port, username='USER', password='PASS',
  16. key_filename='OPTIONAL Address to private Key')
  17.  
  18. baseCommand = "command"
  19. stdin, stdout, stderr = ssh.exec_command('some command')
  20. print(stdout.readlines())
  21. stdin, stdout, stderr = ssh.exec_command(baseCommand + 'ls')
  22. print(stdout.readlines())
  23.  
  24. #for copy file
  25.  
  26. localpath = "local paths" + time.strftime("%Y-%m-%d-%H-%M-%S") + ".sql"; # add a date name for file
  27. remotepath = "remote path"
  28. touch(localpath);
  29. sftp.get(remotepath, localpath) # download the file
  30.  
  31. sftp.close()
  32. ssh.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement