Advertisement
Guest User

Untitled

a guest
Jul 19th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. class SCPClientWrapper(object):
  2.  
  3. def __init__(self, login):
  4. from paramiko import SSHClient, AutoAddPolicy
  5. from scp import SCPClient
  6.  
  7. self.login = login
  8.  
  9. def __enter__(self):
  10. self.client = SSHClient()
  11. self.client.set_missing_host_key_policy(AutoAddPolicy())
  12. self.client.connect(
  13. login["host"],
  14. port = login["port"],
  15. username = login["user"],
  16. password = login["pass"])
  17. return self
  18.  
  19. def __exit__(self, exception_type, exception_value, traceback):
  20. self.client.close()
  21.  
  22. def find_file(self, remote_path):
  23. stdin, stdout, stderr = self.client.exec_command("find %s -type f -maxdepth 1" % remote_path)
  24. return stdout.read().strip("\n").split("\n")[0]
  25.  
  26. def get(self, remote_path, local_path):
  27. with SCPClient(self.client.get_transport()) as scp:
  28. scp.get(remote_path, local_path)
  29.  
  30. def rm(self, remote_path):
  31. self.client.exec_command("rm %s" % remote_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement