def syncProcess(): src_names = [] tar_names= [] #open source connection src_conn_set = sftp_connector.estConnection("localhost","sftp_usr","Password1") src_conn = src_conn_set.openConn() # #open target connection tar_conn_set = sftp_connector.estConnection("localhost","sftp_usr2","Password1",33) tar_conn = tar_conn_set.openConn() # Get the directory and file listing data_src = src_conn.listdir() data_tar = tar_conn.listdir() # Add source files to sync list for i in data_src: if src_conn.isdir(i): src_names.append(i) # Add target to sync list for i in data_tar: if tar_conn.isdir(i): tar_names.append(i) #compare global copyList copyList = list(set(src_names) - set(tar_names)) copyListLen = len(copyList) if copyListLen > 0: log.info(str(copyListLen) + ' directories to be copied...') for copy_dir_name in copyList: if src_conn.isdir(copy_dir_name): #remove local dir checkLocal_content(copy_dir_name) src_conn.get_r(copy_dir_name, local_dir) log.info(copy_dir_name + ' downloaded') tar_conn.put_r(local_dir,'') log.info(str(copyList) + ' uploaded') else: log.info('All folders in sync...nothing to do') #close connections log.info('Source connection status: ' + src_conn_set.host + ':' + str(src_conn_set.port)) closeConnections(src_conn) log.info('Target connection status: ' + tar_conn_set.host + ':' + str(tar_conn_set.port)) closeConnections(tar_conn)
def syncProcess(): src_file_names = [] tar_file_names = [] #open source connection src_conn_set = sftp_connector.estConnection("localhost","sftp_usr","Password1") src_conn = src_conn_set.openConn() # Get the directory and file listing data_src = src_conn.listdir() # Add source dir to sync list for i in data_src: if src_conn.isdir(i): src_file_names.append(i) # Add local dir to sync list tar_file_names = [d for d in os.listdir(local_dir) if os.path.isdir(os.path.join(local_dir, d))] #compare global copyList copyList = list(set(src_file_names) - set(tar_file_names)) copyListLen = len(copyList) if copyListLen > 0: log.info(str(copyListLen) + ' directories to be copied...') for copy_dir_name in copyList: if src_conn.isdir(copy_dir_name): #remove local dir checkLocal_content(copy_dir_name) src_conn.get_r(copy_dir_name, 'local') log.info(copy_dir_name + ' downloaded') else: log.info('All folders in sync...nothing to do') #close connections log.info('Source connection status: ' + src_conn_set.host + ':' + str(src_conn_set.port)) sftp_connector.closeConnections(src_conn)