Fix ssh plugin to correctly fetch files when using scp (#18614)

Fetch module uses fetch_file() from plugin/connection/ssh.py to
retrieve files from the remote hosts which in turns uses
_file_transport_command(self, in_path, out_path, sftp_action) being
sftp_action = 'get'

When using scp rather than sftp, sftp_action variable is not used
and the scp command is formed in a way that the file is always
sent to the remote machine

This patch fixes _file_transport_command() to correctly form the scp
swaping src and dest if sftp_action is 'get'

Bug introduced at 8e47b9b
Fixes #18603

Signed-off-by: Alberto Murillo Silva <alberto.murillo.silva@intel.com>
(cherry picked from commit ec2521f6af)
This commit is contained in:
Alberto Murillo 2016-11-26 16:55:38 -06:00 committed by James Cammarata
parent 8dee7f3138
commit b9a1b2836a

View file

@ -628,6 +628,9 @@ class Connection(ConnectionBase):
cmd = self._build_command('sftp', to_bytes(host)) cmd = self._build_command('sftp', to_bytes(host))
in_data = u"{0} {1} {2}\n".format(sftp_action, pipes.quote(in_path), pipes.quote(out_path)) in_data = u"{0} {1} {2}\n".format(sftp_action, pipes.quote(in_path), pipes.quote(out_path))
elif method == 'scp': elif method == 'scp':
if sftp_action == 'get':
cmd = self._build_command('scp', u'{0}:{1}'.format(host, pipes.quote(out_path)), in_path)
else:
cmd = self._build_command('scp', in_path, u'{0}:{1}'.format(host, pipes.quote(out_path))) cmd = self._build_command('scp', in_path, u'{0}:{1}'.format(host, pipes.quote(out_path)))
in_data = None in_data = None