Skip to content

Commit 5b8ae4e

Browse files
sbngrosssgross-emlix
authored andcommitted
driver/sshdriver: add multifile support to scp
Users are accustomed to scp having an option for copying recursively as well as to accept multiple source files. Meet user expectation by adding well known `-r` option and support for multiple source files.
1 parent 0910748 commit 5b8ae4e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

labgrid/driver/sshdriver.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,24 +356,31 @@ def forward_unix_socket(self, unixsocket, localport=None):
356356
yield localport
357357

358358
@Driver.check_active
359-
@step(args=['src', 'dst'])
360-
def scp(self, *, src, dst):
359+
@step(args=['src', 'dst', 'recursive'])
360+
def scp(self, *, src, dst, recursive=False):
361361
if not self._check_keepalive():
362362
raise ExecutionError("Keepalive no longer running")
363363

364-
if src.startswith(':') == dst.startswith(':'):
365-
raise ValueError("Either source or destination must be remote (start with :)")
366-
if src.startswith(':'):
367-
src = '_' + src
368-
if dst.startswith(':'):
364+
if all([f.startswith(':') for f in src]):
365+
if dst.startswith(':'):
366+
raise ValueError("Either source or destination must be remote (start with :)")
367+
src = ['_' + f for f in src]
368+
else:
369+
if not dst.startswith(':'):
370+
raise ValueError("Either source or destination must be remote (start with :)")
369371
dst = '_' + dst
370372

371373
complete_cmd = [self._scp,
372374
"-S", self._ssh,
373375
"-F", "none",
374376
"-o", f"ControlPath={self.control.replace('%', '%%')}",
375-
src, dst,
377+
dst,
376378
]
379+
for f in src:
380+
complete_cmd.insert(-1, f)
381+
382+
if recursive:
383+
complete_cmd.insert(1, "-r")
377384

378385
if self.explicit_sftp_mode and self._scp_supports_explicit_sftp_mode():
379386
complete_cmd.insert(1, "-s")

0 commit comments

Comments
 (0)