Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import paramiko
  3. import sys,os
  4.  
  5. host = "*.*.*.*"
  6. transport = paramiko.transport.Transport((host))
  7. username = "***"
  8. password = "***"
  9. transport.connect(username = username, password = password)
  10. sftp = paramiko.SFTPClient.from_transport(transport)
  11.  
  12. local_path = sys.argv[1]
  13.  
  14. remote_root_path = "***"
  15.  
  16. remote_folder = "{0}/{1}".format(remote_root_path,sys.argv[2])
  17.  
  18. # if $remote_folder is not exist, then make a folder with name '$remote_folder'
  19. try:
  20. sftp.lstat(remote_folder)
  21. except IOError:
  22. sftp.mkdir(remote_folder)
  23.  
  24. # define a callback of uploading progress
  25. def progress(cur, total):
  26. percent = float(cur) / total
  27. sys.stdout.write('\r[{:.2%}]'.format(percent))
  28. sys.stdout.flush()
  29.  
  30. #upload files in local_path
  31. files = os.listdir(local_path)
  32. for file in files:
  33. print "upload ",file
  34. local_file = os.path.join(local_path,file)
  35. remote_file = os.path.join(remote_folder,file)
  36. sftp.put(local_file,remote_file,callback=progress)
  37.  
  38. sftp.close()
  39. transport.close()
  40.  
  41. print 'All Files Upload Done !'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement