Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SCPClientWrapper(object):
- def __init__(self, login):
- from paramiko import SSHClient, AutoAddPolicy
- from scp import SCPClient
- self.login = login
- def __enter__(self):
- self.client = SSHClient()
- self.client.set_missing_host_key_policy(AutoAddPolicy())
- self.client.connect(
- login["host"],
- port = login["port"],
- username = login["user"],
- password = login["pass"])
- return self
- def __exit__(self, exception_type, exception_value, traceback):
- self.client.close()
- def find_file(self, remote_path):
- stdin, stdout, stderr = self.client.exec_command("find %s -type f -maxdepth 1" % remote_path)
- return stdout.read().strip("\n").split("\n")[0]
- def get(self, remote_path, local_path):
- with SCPClient(self.client.get_transport()) as scp:
- scp.get(remote_path, local_path)
- def rm(self, remote_path):
- self.client.exec_command("rm %s" % remote_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement