Advertisement
Guest User

Untitled

a guest
Aug 18th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #Bandaid for hardcoding of local files
  2.  
  3. ## Be sure to install the paramiko package. 'pip install paramiko'
  4.  
  5. ip = ~~ip address~~
  6. un = ~~username~~
  7. pw = ~~password~~
  8. localdir = "/home/user/sftpfiles/" ## change to your local storage directory
  9.  
  10. import paramiko
  11.  
  12. class sftp_client: #get local directory of a pulled file with "local_filename = ship.files[remote_filename]"
  13.  
  14. def __init__(self, ip, un, pw, localdir):
  15.  
  16. self.ip = ip
  17. self.un = un
  18. self.pw = pw
  19. self.localdir = localdir
  20.  
  21. self.ssh = paramiko.SSHClient()
  22.  
  23. self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  24. self.ssh.load_system_host_keys()
  25.  
  26. self.ssh.connect(ip,username=un, password=pw, key_filename = key_file)
  27.  
  28. self.sftp = self.ssh.open_sftp()
  29. self.files = {}
  30.  
  31. def get_file(self,filename):
  32.  
  33. localpath = localdir+filename.split('/')[-1]
  34. self.sftp.get(filename, localpath)
  35. self.files[filename]=localpath
  36.  
  37.  
  38. ship = sftp_client(ip,un,pw,localdir)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement