<jupyter_start><jupyter_text>AbstractA tiny utility to copy a batch of files via SCP.<jupyter_code>import sys
import glob
import subprocess

def batch_scp(source, target, match_str_list):
    
    source_file_list = glob.glob(source)
    filtered_file_list = []
    
    for file in source_file_list:
        if (any(word in file for word in match_str_list)):
            filtered_file_list.append(file)
    
    print('total_files: {0} filtered_files: {1}'.format(
        len(source_file_list), len(filtered_file_list)))

    file_num = len(filtered_file_list)
    
    # change the order of files, which might help with the recovery if failure
    filtered_file_list.sort()
    
    for index, file in enumerate(filtered_file_list):
        
        command = ['scp', file, target]
        print("[{0}/{1}] {2}".format(index, file_num, " ".join(command)))
        subprocess.call(command)


if __name__ == "__main__":
    
    source = sys.argv[1]
    target = sys.argv[2]

    match_str_list = ['DLH', 'AFR', 'MAS']
    
    batch_scp(source, target, match_str_list)
match_str_list = ['DLH']
source_folder = "./*"
#dest_folder = 'username@hostname:/tmp/'
dest_folder = 'lguo@nceinrlnx01:/tmp/'

batch_scp(source_folder, dest_folder, match_str_list)<jupyter_output>total_files: 33 filtered_files: 2
[0/2] scp ./test.DLH.201802 lguo@nceinrlnx01:/tmp/
[1/2] scp ./test.DLH.201803 lguo@nceinrlnx01:/tmp/
{'fraction_non_alphanumeric': 0.1247327156094084, 'fraction_numerical': 0.022808267997148968, 'mean_word_length': 3.6184210526315788, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '262957', 'license': 'Apache-2.0', 'n_tokens_mistral': 529, 'n_tokens_neox': 504, 'n_words': 107, 'path': 'scp_batch.ipynb', 'repo_name': 'liaison/python', 'size': '1403'}