Skip to content

Commit f525ed0

Browse files
MalandrilThomas Canava
andauthored
Allow custom scp download command line (hierynomus#958)
Co-authored-by: Thomas Canava <thomas.canava@soprasteria.com>
1 parent 93046f3 commit f525ed0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/main/java/net/schmizz/sshj/xfer/scp/SCPDownloadClient.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,20 @@ public synchronized int copy(String sourcePath, LocalDestFile targetFile) throws
4545

4646
public synchronized int copy(String sourcePath, LocalDestFile targetFile, ScpCommandLine.EscapeMode escapeMode)
4747
throws IOException {
48+
ScpCommandLine commandLine = ScpCommandLine.with(ScpCommandLine.Arg.SOURCE)
49+
.and(ScpCommandLine.Arg.QUIET)
50+
.and(ScpCommandLine.Arg.PRESERVE_TIMES)
51+
.and(ScpCommandLine.Arg.RECURSIVE, recursiveMode)
52+
.and(ScpCommandLine.Arg.LIMIT, String.valueOf(bandwidthLimit), (bandwidthLimit > 0));
53+
return copy(sourcePath, targetFile, escapeMode, commandLine);
54+
}
55+
56+
public synchronized int copy(String sourcePath, LocalDestFile targetFile, ScpCommandLine.EscapeMode escapeMode, ScpCommandLine commandLine)
57+
throws IOException {
4858
engine.cleanSlate();
4959
try {
50-
startCopy(sourcePath, targetFile, escapeMode);
60+
commandLine.withPath(sourcePath, escapeMode);
61+
startCopy(targetFile, commandLine);
5162
} finally {
5263
engine.exit();
5364
}
@@ -62,14 +73,7 @@ public void setRecursiveMode(boolean recursive) {
6273
this.recursiveMode = recursive;
6374
}
6475

65-
private void startCopy(String sourcePath, LocalDestFile targetFile, ScpCommandLine.EscapeMode escapeMode)
66-
throws IOException {
67-
ScpCommandLine commandLine = ScpCommandLine.with(ScpCommandLine.Arg.SOURCE)
68-
.and(ScpCommandLine.Arg.QUIET)
69-
.and(ScpCommandLine.Arg.PRESERVE_TIMES)
70-
.and(ScpCommandLine.Arg.RECURSIVE, recursiveMode)
71-
.and(ScpCommandLine.Arg.LIMIT, String.valueOf(bandwidthLimit), (bandwidthLimit > 0));
72-
commandLine.withPath(sourcePath, escapeMode);
76+
private void startCopy(LocalDestFile targetFile, ScpCommandLine commandLine) throws IOException {
7377
engine.execSCPWith(commandLine);
7478

7579
engine.signal("Start status OK");

0 commit comments

Comments
 (0)