Guest User

Untitled

a guest
Feb 11th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import socket
  2. import sys
  3. import traceback
  4. import paramiko
  5.  
  6. # setup logging
  7. paramiko.util.log_to_file('ftp.log')
  8.  
  9. # SFTP configuration
  10. hostname = 'demo.wftpserver.com'
  11. port = 2222
  12. username = 'demo-user'
  13. password = 'demo-user'
  14.  
  15. # Files configuration
  16. src_file = 'C:/Home/_Oleg/projects/sftp-ku/research.py'
  17. sftp_base_dir = 'upload/'
  18. out_file_name = 'research4.py'
  19.  
  20.  
  21. try:
  22. t = paramiko.Transport((hostname, port))
  23. t.connect(None, username, password, gss_host=socket.getfqdn(hostname))
  24. sftp = paramiko.SFTPClient.from_transport(t)
  25.  
  26. dirlist = sftp.listdir('.')
  27. print("Dirlist: %s" % dirlist)
  28.  
  29. sftp.put(src_file, '{}{}'.format(sftp_base_dir, out_file_name))
  30. t.close()
  31.  
  32. except Exception as e:
  33. print('*** Caught exception: %s: %s' % (e.__class__, e))
  34. traceback.print_exc()
  35. try:
  36. t.close()
  37. except:
  38. pass
  39.  
  40. sys.exit(1)
Add Comment
Please, Sign In to add comment