Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paramiko
- sftpURL = 'sftp.somewebsite.com'
- sftpUser = 'user_name'
- sftpPass = 'password'
- ssh = paramiko.SSHClient()
- # automatically add keys without requiring human intervention
- ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy() )
- ssh.connect(sftpURL, username=sftpUser, password=sftpPass)
- ftp = ssh.open_sftp()
- files = ftp.listdir()
- print files
- ['.bash_logout', '.bash_profile', '.bashrc', '.mozilla', 'testfile_248.xml']
- >>> for i in ftp.listdir():
- ... lstatout=str(ftp.lstat(i)).split()[0]
- ... if 'd' in lstatout: print i, 'is a directory'
- ...
- >>> for i in ftp.listdir():
- ... lstatout=str(ftp.lstat(i)).split()[0]
- ... if 'd' not in lstatout: print i, 'is a file'
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement