ffdc: Add scp plugin.
- Set 1: Initial code
- Set 2: Expand comments
- Set 2: Allow filename to be either list-of-filenames or just filename
Test:
- Tested standalone plugin to SSH/SCP remote hosts.
Signed-off-by: Peter D Phan <peterp@us.ibm.com>
Change-Id: If85d4b06b5da05f7403a3af28fa15a6d7f6c5925
diff --git a/ffdc/plugins/scp_execution.py b/ffdc/plugins/scp_execution.py
new file mode 100644
index 0000000..859925f
--- /dev/null
+++ b/ffdc/plugins/scp_execution.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+
+import os
+import sys
+
+# ---------Set sys.path for pluqin execution---------------------------------------
+# Absolute path to this plugin
+abs_path = os.path.abspath(os.path.dirname(sys.argv[0]))
+# full_path to plugins parent directory
+full_path = abs_path.split('plugins')[0]
+sys.path.append(full_path)
+# Walk path and append to sys.path
+for root, dirs, files in os.walk(full_path):
+ for found_dir in dirs:
+ sys.path.append(os.path.join(root, found_dir))
+
+# ssh_utility is in ../lib
+from ssh_utility import SSHRemoteclient
+
+
+def scp_remote_file(hostname,
+ username,
+ password,
+ filename,
+ local_dir_path):
+ r"""
+ Description of argument(s):
+
+ hostname Name/IP of the remote (targeting) host
+ username User on the remote host with access to files
+ password Password for user on remote host
+ filename Filename with full path on remote host
+ Filename can contain wild cards for multiple files
+ local_dir_path Location to store file on local host
+ """
+ ssh_remoteclient = SSHRemoteclient(hostname,
+ username,
+ password)
+
+ if ssh_remoteclient.ssh_remoteclient_login():
+
+ # Obtain scp connection.
+ ssh_remoteclient.scp_connection()
+ if ssh_remoteclient.scpclient:
+ if isinstance(filename, list):
+ for each_file in filename:
+ ssh_remoteclient.scp_file_from_remote(each_file, local_dir_path)
+ else:
+ ssh_remoteclient.scp_file_from_remote(filename, local_dir_path)
+
+ # Close ssh/scp session
+ if ssh_remoteclient:
+ ssh_remoteclient.ssh_remoteclient_disconnect()