-
Notifications
You must be signed in to change notification settings - Fork 1
/
remote.py
29 lines (24 loc) · 879 Bytes
/
remote.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from paramiko import SSHClient, AutoAddPolicy
class Remote:
def __init__(self, host, user, password):
self.host = host
self.user = user
self.password = password
self.client = SSHClient()
self.client.set_missing_host_key_policy(AutoAddPolicy())
def connect(self):
self.client.connect(self.host, username=self.user, password=self.password)
def close(self):
self.client.close()
def load_data(self, remote_path, buffer_path):
self.connect()
ftp_client = self.client.open_sftp()
ftp_client.get(remote_path, buffer_path)
ftp_client.close()
self.close()
def save_data(self, buffer_path, remote_path):
self.connect()
ftp_client = self.client.open_sftp()
ftp_client.put(buffer_path, remote_path)
ftp_client.close()
self.close()