X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2Fssh.py;h=ca6d6556a139db442fa7096443e67d79a4c05f5d;hp=db39a0701c8599e62474afe4c0e75345b0f1e887;hb=d32194f3afb0ec725d178effe6ae589571287602;hpb=4a946c16a4935e52b3e9039e4661813c256a8934 diff --git a/resources/libraries/python/ssh.py b/resources/libraries/python/ssh.py index db39a0701c..ca6d6556a1 100644 --- a/resources/libraries/python/ssh.py +++ b/resources/libraries/python/ssh.py @@ -307,17 +307,35 @@ class SSH(object): """ chan.close() - def scp(self, local_path, remote_path): - """Copy files from local_path to remote_path. + def scp(self, local_path, remote_path, get=False): + """Copy files from local_path to remote_path or vice versa. connect() method has to be called first! + + :param local_path: Path to local file that should be uploaded; or + path where to save remote file. + :param remote_path: Remote path where to place uploaded file; or + path to remote file which should be downloaded. + :param get: scp operation to perform. Default is put. + :type local_path: str + :type remote_path: str + :type get: bool """ - logger.trace('SCP {0} to {1}:{2}'.format( - local_path, self._ssh.get_transport().getpeername(), remote_path)) + if not get: + logger.trace('SCP {0} to {1}:{2}'.format( + local_path, self._ssh.get_transport().getpeername(), + remote_path)) + else: + logger.trace('SCP {0}:{1} to {2}'.format( + self._ssh.get_transport().getpeername(), remote_path, + local_path)) # SCPCLient takes a paramiko transport as its only argument scp = SCPClient(self._ssh.get_transport(), socket_timeout=10) start = time() - scp.put(local_path, remote_path) + if not get: + scp.put(local_path, remote_path) + else: + scp.get(remote_path, local_path) scp.close() end = time() logger.trace('SCP took {0} seconds'.format(end-start))