Guest User

Untitled

a guest
Nov 18th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import paramiko
  4. import fnmatch
  5. import os
  6. import glob
  7. from stat import S_ISDIR
  8. from datetime import datetime,timedelta
  9.  
  10. paramiko.util.log_to_file('logfileIN.log')
  11.  
  12. host = "192.168.244.8"
  13. port = 22
  14. transport = paramiko.Transport((host, port))
  15. password = "artobj21"
  16. username = "platine"
  17. transport.connect(username = username, password = password)
  18. sftp = paramiko.SFTPClient.from_transport(transport)
  19.  
  20. local_dir = '/home/inbox/ZTEIN/'
  21. remote_dir = '/data/REFA/coll/data_c/DWH_ZTEIN/'
  22.  
  23. yesterday = (datetime.now() - timedelta(days=1)).strftime("%Y%m%d")
  24. cdrfile= '*'+ str(yesterday)+'*.r'
  25.  
  26. def serv_dir(remote_dir, local_dir):
  27. os.path.exists(local_dir) or os.makedirs(local_dir)
  28. rm_dir = sftp.listdir_attr(remote_dir)
  29. for item in rm_dir:
  30. # assuming the local system is Windows and the remote system is Linux
  31. # os.path.join won't help here, so construct remote_path manually
  32. if fnmatch.fnmatch(item.filename, cdrfile):
  33. remote_path = remote_dir + '/' + item.filename
  34. local_path = os.path.join(local_dir, item.filename)
  35. if S_ISDIR(item.st_mode):
  36. serv_dir(remote_path, local_path)
  37. else:
  38. sftp.get(remote_path, local_path)
  39.  
  40.  
  41. serv_dir("/data/REFA/coll/data_c/DWH_ZTEIN/","/home/inbox/ZTEIN/")
  42.  
  43. sftp.close()
  44. transport.close()
Add Comment
Please, Sign In to add comment