Skip to content

Commit b1f68a7

Browse files
Rahbek, Nikolaj (EXT) (SGRE OF TE TD LC SLC CMI)Bastian-Krause
authored andcommitted
fix sftp option for scp
The option to use sftp was added multiple times when using SSHDriver::put() and SSHDriver::get() causing them to only work one time. Also adds the sftp option to SSHDriver::scp(). Signed-off-by: Nikolaj Rahbek <nikolaj@b2vn.org> [bst: cherry-picked from commit c0016b0] Signed-off-by: Bastian Krause <bst@pengutronix.de>
1 parent c773a8f commit b1f68a7

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

CHANGES.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Bug fixes in 23.0.1
1313
ERROR, INFO and similar log notifiers.
1414
- Fix named SSH lookups in conjunction with an environment file in
1515
labgrid-client.
16-
1716

1817
Release 23.0 (Released Apr 24, 2023)
1918
------------------------------------

labgrid/driver/sshdriver.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ def scp(self, *, src, dst):
328328
"-o", f"ControlPath={self.control.replace('%', '%%')}",
329329
src, dst,
330330
]
331+
332+
if self.explicit_sftp_mode and self._scp_supports_explicit_sftp_mode():
333+
complete_cmd.insert(1, "-s")
334+
331335
self.logger.info("Running command: %s", complete_cmd)
332336
sub = subprocess.Popen(
333337
complete_cmd,
@@ -415,18 +419,18 @@ def _scp_supports_explicit_sftp_mode(self):
415419
@Driver.check_active
416420
@step(args=['filename', 'remotepath'])
417421
def put(self, filename, remotepath=''):
418-
ssh_prefix = self.ssh_prefix
419-
if self.explicit_sftp_mode and self._scp_supports_explicit_sftp_mode():
420-
ssh_prefix.append("-s")
421422
transfer_cmd = [
422423
"scp",
423-
*ssh_prefix,
424+
*self.ssh_prefix,
424425
"-P", str(self.networkservice.port),
425426
"-r",
426427
filename,
427428
f"{self.networkservice.username}@{self.networkservice.address}:{remotepath}"
428429
]
429430

431+
if self.explicit_sftp_mode and self._scp_supports_explicit_sftp_mode():
432+
transfer_cmd.insert(1, "-s")
433+
430434
try:
431435
sub = subprocess.call(
432436
transfer_cmd
@@ -443,18 +447,18 @@ def put(self, filename, remotepath=''):
443447
@Driver.check_active
444448
@step(args=['filename', 'destination'])
445449
def get(self, filename, destination="."):
446-
ssh_prefix = self.ssh_prefix
447-
if self.explicit_sftp_mode and self._scp_supports_explicit_sftp_mode():
448-
ssh_prefix.append("-s")
449450
transfer_cmd = [
450451
"scp",
451-
*ssh_prefix,
452+
*self.ssh_prefix,
452453
"-P", str(self.networkservice.port),
453454
"-r",
454455
f"{self.networkservice.username}@{self.networkservice.address}:{filename}",
455456
destination
456457
]
457458

459+
if self.explicit_sftp_mode and self._scp_supports_explicit_sftp_mode():
460+
transfer_cmd.insert(1, "-s")
461+
458462
try:
459463
sub = subprocess.call(
460464
transfer_cmd

0 commit comments

Comments
 (0)