1#!/usr/bin/env python3 2 3 4# ssh_utility is in ../lib 5from ssh_utility import SSHRemoteclient 6 7import os 8import sys 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, 25 username, 26 password, 27 filename, 28 local_dir_path): 29 r""" 30 Description of argument(s): 31 32 hostname Name/IP of the remote (targeting) host 33 username User on the remote host with access to files 34 password Password for user on remote host 35 filename Filename with full path on remote host 36 Filename can contain wild cards for multiple files 37 local_dir_path Location to store file on local host 38 """ 39 ssh_remoteclient = SSHRemoteclient(hostname, 40 username, 41 password) 42 43 if ssh_remoteclient.ssh_remoteclient_login(): 44 45 # Obtain scp connection. 46 ssh_remoteclient.scp_connection() 47 if ssh_remoteclient.scpclient: 48 if isinstance(filename, list): 49 for each_file in filename: 50 ssh_remoteclient.scp_file_from_remote(each_file, local_dir_path) 51 else: 52 ssh_remoteclient.scp_file_from_remote(filename, local_dir_path) 53 54 # Close ssh/scp session 55 if ssh_remoteclient: 56 ssh_remoteclient.ssh_remoteclient_disconnect() 57