Guest User

Untitled

a guest
Aug 9th, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import paramiko
  2.  
  3.  
  4. class SFTPClient:
  5. """ftp over ssh"""
  6.  
  7. def __init__(self, hostname, port, user, password):
  8. """
  9. constructor, gonna connect to the ssh server
  10. :param hostname:
  11. :param port:
  12. :param user:
  13. :param password:
  14. """
  15. self.ssh = paramiko.SSHClient()
  16. self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  17. self.ssh.connect(hostname, port, user, paramiko)
  18. self.sftp = self.ssh.open_sftp() # sftp channel for the communication
  19.  
  20. def upload(self, file_name):
  21. self.sftp.put(file_name, file_name)
  22. print("{} : done uploading".format(file_name))
  23.  
  24. def __del__(self):
  25. self.sftp.close()
  26. self.ssh.close()
  27.  
  28.  
  29. ssh = SFTPClient('localhost', 22, 'training', 'training')
  30. ssh.upload('pssshclient2.py')
Add Comment
Please, Sign In to add comment