Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import paramiko
- import fnmatch
- import os
- import glob
- from stat import S_ISDIR
- from datetime import datetime,timedelta
- paramiko.util.log_to_file('logfileIN.log')
- host = "192.168.244.8"
- port = 22
- transport = paramiko.Transport((host, port))
- password = "artobj21"
- username = "platine"
- transport.connect(username = username, password = password)
- sftp = paramiko.SFTPClient.from_transport(transport)
- local_dir = '/home/inbox/ZTEIN/'
- remote_dir = '/data/REFA/coll/data_c/DWH_ZTEIN/'
- yesterday = (datetime.now() - timedelta(days=1)).strftime("%Y%m%d")
- cdrfile= '*'+ str(yesterday)+'*.r'
- def serv_dir(remote_dir, local_dir):
- os.path.exists(local_dir) or os.makedirs(local_dir)
- rm_dir = sftp.listdir_attr(remote_dir)
- for item in rm_dir:
- # assuming the local system is Windows and the remote system is Linux
- # os.path.join won't help here, so construct remote_path manually
- if fnmatch.fnmatch(item.filename, cdrfile):
- remote_path = remote_dir + '/' + item.filename
- local_path = os.path.join(local_dir, item.filename)
- if S_ISDIR(item.st_mode):
- serv_dir(remote_path, local_path)
- else:
- sftp.get(remote_path, local_path)
- serv_dir("/data/REFA/coll/data_c/DWH_ZTEIN/","/home/inbox/ZTEIN/")
- sftp.close()
- transport.close()
Add Comment
Please, Sign In to add comment