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