Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # http://pysftp.readthedocs.io/en/release_0.2.8/cookbook.html#pysftp-connection-pwd
- import pysftp
- with pysftp.Connection('54.191.120.184', username='ubuntu', private_key='/home/asm/Downloads/test_smtp.pem') as sftp:
- # sftp.put_d('/home/asm/Documents/sftp_task/files/', 'var/www/files/', preserve_mtime=True)
- with sftp.cd('var'): # now in ./static
- sftp.chdir('www') # now in ./static/here
- sftp.chdir('files') # now in ./static/here/there
- print sftp.listdir()
- print sftp.getcwd()
- print sftp.pwd
- sftp.get_d('var/www/files/', '/home/asm/Documents/sftp_task/file_backup/', preserve_mtime=True)
- # Closes the connection
- sftp.close()
- # import paramiko
- # paramiko.util.log_to_file('/tmp/paramiko.log')
- # # Open a transport
- # host = "example.com"
- # port = 22
- # transport = paramiko.Transport((host, port))
- # # Auth
- # password = "foo"
- # username = "bar"
- # transport.connect(username = username, password = password)
- # # Go!
- # sftp = paramiko.SFTPClient.from_transport(transport)
- # # Download
- # filepath = '/etc/passwd'
- # localpath = '/home/remotepasswd'
- # sftp.get(filepath, localpath)
- # # Upload
- # filepath = '/home/foo.jpg'
- # localpath = '/home/pony.jpg'
- # sftp.put(localpath, filepath)
- # # Close
- # sftp.close()
- # transport.close()
Add Comment
Please, Sign In to add comment