Advertisement
Guest User

Untitled

a guest
Feb 25th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import paramiko
  2.  
  3. sftpURL = 'sftp.somewebsite.com'
  4. sftpUser = 'user_name'
  5. sftpPass = 'password'
  6.  
  7. ssh = paramiko.SSHClient()
  8. # automatically add keys without requiring human intervention
  9. ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy() )
  10.  
  11. ssh.connect(sftpURL, username=sftpUser, password=sftpPass)
  12.  
  13. ftp = ssh.open_sftp()
  14. files = ftp.listdir()
  15. print files
  16.  
  17. ['.bash_logout', '.bash_profile', '.bashrc', '.mozilla', 'testfile_248.xml']
  18.  
  19. >>> for i in ftp.listdir():
  20. ... lstatout=str(ftp.lstat(i)).split()[0]
  21. ... if 'd' in lstatout: print i, 'is a directory'
  22. ...
  23.  
  24. >>> for i in ftp.listdir():
  25. ... lstatout=str(ftp.lstat(i)).split()[0]
  26. ... if 'd' not in lstatout: print i, 'is a file'
  27. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement