Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paramiko
- class SFTPClient:
- """ftp over ssh"""
- def __init__(self, hostname, port, user, password):
- """
- constructor, gonna connect to the ssh server
- :param hostname:
- :param port:
- :param user:
- :param password:
- """
- self.ssh = paramiko.SSHClient()
- self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- self.ssh.connect(hostname, port, user, paramiko)
- self.sftp = self.ssh.open_sftp() # sftp channel for the communication
- def upload(self, file_name):
- self.sftp.put(file_name, file_name)
- print("{} : done uploading".format(file_name))
- def __del__(self):
- self.sftp.close()
- self.ssh.close()
- ssh = SFTPClient('localhost', 22, 'training', 'training')
- ssh.upload('pssshclient2.py')
Add Comment
Please, Sign In to add comment