import paramiko
from config import rest_config

class CustomSFTPClient():
    def __init__(self):
        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
        
        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':
    sftp_client = CustomSFTPClient()