Files
GLASSES_AI_SERVER/utils/custom_sftp.py

31 lines
983 B
Python
Raw Normal View History

2025-04-28 14:23:46 +09:00
import paramiko
from config import rest_config
2025-04-28 14:23:46 +09:00
class CustomSFTPClient():
def __init__(self):
2025-07-08 17:20:32 +09:00
from config import rest_config
host = rest_config.sftp_host
port = rest_config.sftp_port
id = rest_config.sftp_id
pw = rest_config.sftp_pw
2025-04-28 14:23:46 +09:00
self.ssh_client = paramiko.SSHClient()
self.ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.ssh_client.connect(hostname=host, port=port, username=id, password=pw)
self.sftp_client = self.ssh_client.open_sftp()
def remote_mkdir(self, remote_path):
self.sftp_client.mkdir(remote_path)
def remote_copy_data(self,local_path, remote_path):
self.sftp_client.put(local_path, remote_path)
def client_close(self):
self.sftp_client.close()
self.ssh_client.close()
sftp_client = None
if sftp_client is None and rest_config.config != 'release':
2025-04-28 14:23:46 +09:00
sftp_client = CustomSFTPClient()