1#!/usr/bin/env python3 2 3 4import os 5import sys 6 7# ssh_utility is in ../lib 8from ssh_utility import SSHRemoteclient 9 10# ---------Set sys.path for pluqin execution--------------------------------------- 11# Absolute path to this plugin 12abs_path = os.path.abspath(os.path.dirname(sys.argv[0])) 13 14# full_path to plugins parent directory 15full_path = abs_path.split("plugins")[0] 16sys.path.append(full_path) 17 18# Walk path and append to sys.path 19for root, dirs, files in os.walk(full_path): 20 for found_dir in dirs: 21 sys.path.append(os.path.join(root, found_dir)) 22 23 24def scp_remote_file(hostname, username, password, filename, local_dir_path): 25 r""" 26 Description of argument(s): 27 28 hostname Name/IP of the remote (targeting) host 29 username User on the remote host with access to files 30 password Password for user on remote host 31 filename Filename with full path on remote host 32 Filename can contain wild cards for multiple files 33 local_dir_path Location to store file on local host 34 """ 35 ssh_remoteclient = SSHRemoteclient(hostname, username, password) 36 37 if ssh_remoteclient.ssh_remoteclient_login(): 38 # Obtain scp connection. 39 ssh_remoteclient.scp_connection() 40 if ssh_remoteclient.scpclient: 41 if isinstance(filename, list): 42 for each_file in filename: 43 ssh_remoteclient.scp_file_from_remote( 44 each_file, local_dir_path 45 ) 46 else: 47 ssh_remoteclient.scp_file_from_remote(filename, local_dir_path) 48 49 # Close ssh/scp session 50 if ssh_remoteclient: 51 ssh_remoteclient.ssh_remoteclient_disconnect() 52