Guest User

Untitled

a guest
Mar 26th, 2018
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. # http://pysftp.readthedocs.io/en/release_0.2.8/cookbook.html#pysftp-connection-pwd
  2. import pysftp
  3.  
  4. with pysftp.Connection('54.191.120.184', username='ubuntu', private_key='/home/asm/Downloads/test_smtp.pem') as sftp:
  5. # sftp.put_d('/home/asm/Documents/sftp_task/files/', 'var/www/files/', preserve_mtime=True)
  6. with sftp.cd('var'): # now in ./static
  7. sftp.chdir('www') # now in ./static/here
  8. sftp.chdir('files') # now in ./static/here/there
  9. print sftp.listdir()
  10. print sftp.getcwd()
  11. print sftp.pwd
  12.  
  13. sftp.get_d('var/www/files/', '/home/asm/Documents/sftp_task/file_backup/', preserve_mtime=True)
  14.  
  15. # Closes the connection
  16. sftp.close()
  17.  
  18.  
  19. # import paramiko
  20. # paramiko.util.log_to_file('/tmp/paramiko.log')
  21.  
  22. # # Open a transport
  23.  
  24. # host = "example.com"
  25. # port = 22
  26. # transport = paramiko.Transport((host, port))
  27.  
  28. # # Auth
  29.  
  30. # password = "foo"
  31. # username = "bar"
  32. # transport.connect(username = username, password = password)
  33.  
  34. # # Go!
  35.  
  36. # sftp = paramiko.SFTPClient.from_transport(transport)
  37.  
  38. # # Download
  39.  
  40. # filepath = '/etc/passwd'
  41. # localpath = '/home/remotepasswd'
  42. # sftp.get(filepath, localpath)
  43.  
  44. # # Upload
  45.  
  46. # filepath = '/home/foo.jpg'
  47. # localpath = '/home/pony.jpg'
  48. # sftp.put(localpath, filepath)
  49.  
  50. # # Close
  51.  
  52. # sftp.close()
  53. # transport.close()
Add Comment
Please, Sign In to add comment