From f525ed0e5ba68f0ca0c1071e997d19468780a2ef Mon Sep 17 00:00:00 2001 From: Thomas Canava Date: Fri, 23 Aug 2024 09:56:39 +0200 Subject: [PATCH] Allow custom scp download command line (#958) Co-authored-by: Thomas Canava --- .../sshj/xfer/scp/SCPDownloadClient.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/schmizz/sshj/xfer/scp/SCPDownloadClient.java b/src/main/java/net/schmizz/sshj/xfer/scp/SCPDownloadClient.java index f9779497f..610e0fb78 100644 --- a/src/main/java/net/schmizz/sshj/xfer/scp/SCPDownloadClient.java +++ b/src/main/java/net/schmizz/sshj/xfer/scp/SCPDownloadClient.java @@ -45,9 +45,20 @@ public synchronized int copy(String sourcePath, LocalDestFile targetFile) throws public synchronized int copy(String sourcePath, LocalDestFile targetFile, ScpCommandLine.EscapeMode escapeMode) throws IOException { + ScpCommandLine commandLine = ScpCommandLine.with(ScpCommandLine.Arg.SOURCE) + .and(ScpCommandLine.Arg.QUIET) + .and(ScpCommandLine.Arg.PRESERVE_TIMES) + .and(ScpCommandLine.Arg.RECURSIVE, recursiveMode) + .and(ScpCommandLine.Arg.LIMIT, String.valueOf(bandwidthLimit), (bandwidthLimit > 0)); + return copy(sourcePath, targetFile, escapeMode, commandLine); + } + + public synchronized int copy(String sourcePath, LocalDestFile targetFile, ScpCommandLine.EscapeMode escapeMode, ScpCommandLine commandLine) + throws IOException { engine.cleanSlate(); try { - startCopy(sourcePath, targetFile, escapeMode); + commandLine.withPath(sourcePath, escapeMode); + startCopy(targetFile, commandLine); } finally { engine.exit(); } @@ -62,14 +73,7 @@ public void setRecursiveMode(boolean recursive) { this.recursiveMode = recursive; } - private void startCopy(String sourcePath, LocalDestFile targetFile, ScpCommandLine.EscapeMode escapeMode) - throws IOException { - ScpCommandLine commandLine = ScpCommandLine.with(ScpCommandLine.Arg.SOURCE) - .and(ScpCommandLine.Arg.QUIET) - .and(ScpCommandLine.Arg.PRESERVE_TIMES) - .and(ScpCommandLine.Arg.RECURSIVE, recursiveMode) - .and(ScpCommandLine.Arg.LIMIT, String.valueOf(bandwidthLimit), (bandwidthLimit > 0)); - commandLine.withPath(sourcePath, escapeMode); + private void startCopy(LocalDestFile targetFile, ScpCommandLine commandLine) throws IOException { engine.execSCPWith(commandLine); engine.signal("Start status OK");