From 782ff9b83e71947b2cd57f30c9ee35b1088008c3 Mon Sep 17 00:00:00 2001 From: lguerin Date: Wed, 12 Aug 2015 16:55:08 +0200 Subject: [PATCH 1/6] Add an option to limit the used bandwidth with SCP upload and download features --- .../sshj/xfer/scp/AbstractSCPClient.java | 16 ++++ .../sshj/xfer/scp/SCPDownloadClient.java | 25 +++--- .../net/schmizz/sshj/xfer/scp/SCPEngine.java | 78 +++++++++++++++++- .../sshj/xfer/scp/SCPFileTransfer.java | 15 +++- .../sshj/xfer/scp/SCPUploadClient.java | 22 +++-- .../sshj/xfer/scp/SCPFileTransferTest.java | 82 +++++++++++++++++++ 6 files changed, 214 insertions(+), 24 deletions(-) create mode 100644 src/main/java/net/schmizz/sshj/xfer/scp/AbstractSCPClient.java create mode 100644 src/test/java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java diff --git a/src/main/java/net/schmizz/sshj/xfer/scp/AbstractSCPClient.java b/src/main/java/net/schmizz/sshj/xfer/scp/AbstractSCPClient.java new file mode 100644 index 000000000..af455da07 --- /dev/null +++ b/src/main/java/net/schmizz/sshj/xfer/scp/AbstractSCPClient.java @@ -0,0 +1,16 @@ +package net.schmizz.sshj.xfer.scp; + +abstract class AbstractSCPClient { + + protected final SCPEngine engine; + protected int bandwidthLimit; + + AbstractSCPClient(SCPEngine engine) { + this.engine = engine; + } + + AbstractSCPClient(SCPEngine engine, int bandwidthLimit) { + this.engine = engine; + this.bandwidthLimit = bandwidthLimit; + } +} 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 c2ad4258b..7d80c5e20 100644 --- a/src/main/java/net/schmizz/sshj/xfer/scp/SCPDownloadClient.java +++ b/src/main/java/net/schmizz/sshj/xfer/scp/SCPDownloadClient.java @@ -24,18 +24,21 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; import java.util.List; +import static net.schmizz.sshj.xfer.scp.SCPEngine.SCPArguments; + /** Support for uploading files over a connected link using SCP. */ -public final class SCPDownloadClient { +public final class SCPDownloadClient extends AbstractSCPClient { private boolean recursiveMode = true; - private final SCPEngine engine; - SCPDownloadClient(SCPEngine engine) { - this.engine = engine; + super(engine); + } + + SCPDownloadClient(SCPEngine engine, int bandwidthLimit) { + super(engine, bandwidthLimit); } /** Download a file from {@code sourcePath} on the connected host to {@code targetPath} locally. */ @@ -60,12 +63,12 @@ public void setRecursiveMode(boolean recursive) { void startCopy(String sourcePath, LocalDestFile targetFile) throws IOException { - List args = new LinkedList(); - args.add(Arg.SOURCE); - args.add(Arg.QUIET); - args.add(Arg.PRESERVE_TIMES); - if (recursiveMode) - args.add(Arg.RECURSIVE); + List args = SCPArguments.with(Arg.SOURCE) + .and(Arg.QUIET) + .and(Arg.PRESERVE_TIMES) + .and(Arg.RECURSIVE, recursiveMode) + .and(Arg.LIMIT, String.valueOf(bandwidthLimit), (bandwidthLimit > 0)) + .arguments(); engine.execSCPWith(args, sourcePath); engine.signal("Start status OK"); diff --git a/src/main/java/net/schmizz/sshj/xfer/scp/SCPEngine.java b/src/main/java/net/schmizz/sshj/xfer/scp/SCPEngine.java index 66bac99dd..78d7eff69 100644 --- a/src/main/java/net/schmizz/sshj/xfer/scp/SCPEngine.java +++ b/src/main/java/net/schmizz/sshj/xfer/scp/SCPEngine.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.LinkedList; import java.util.List; /** @see SCP Protocol */ @@ -39,17 +40,31 @@ enum Arg { RECURSIVE('r'), VERBOSE('v'), PRESERVE_TIMES('p'), - QUIET('q'); + QUIET('q'), + LIMIT('l', ""); private final char a; + private String v; private Arg(char a) { this.a = a; } + private Arg(char a, String v) { + this.a = a; + this.v = v; + } + + public void setValue(String v) { + this.v = v; + } @Override public String toString() { - return "-" + a; + String arg = "-" + a; + if (v != null && v.length() > 0) { + arg = arg + v; + } + return arg; } } @@ -186,4 +201,63 @@ TransferListener getTransferListener() { return listener; } + public static class SCPArguments { + + private static List args = null; + + private SCPArguments() { + this.args = new LinkedList(); + } + + private static void addArg(Arg arg, String value, boolean accept) { + if (accept) { + if (null != value && value.length() > 0) { + arg.setValue(value); + } + args.add(arg); + } + } + + public static SCPArguments with(Arg arg) { + return with(arg, null, true); + } + + public static SCPArguments with(Arg arg, String value) { + return with(arg, value, true); + } + + public static SCPArguments with(Arg arg, boolean accept) { + return with(arg, null, accept); + } + + public static SCPArguments with(Arg arg, String value, boolean accept) { + SCPArguments scpArguments = new SCPArguments(); + addArg(arg, value, accept); + return scpArguments; + } + + public SCPArguments and(Arg arg) { + addArg(arg, null, true); + return this; + } + + public SCPArguments and(Arg arg, String value) { + addArg(arg, value, true); + return this; + } + + public SCPArguments and(Arg arg, boolean accept) { + addArg(arg, null, accept); + return this; + } + + public SCPArguments and(Arg arg, String value, boolean accept) { + addArg(arg, value, accept); + return this; + } + + public List arguments() { + return args; + } + } } diff --git a/src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java b/src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java index 7e055e3bb..a71371c87 100644 --- a/src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java +++ b/src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java @@ -28,18 +28,23 @@ public class SCPFileTransfer extends AbstractFileTransfer implements FileTransfer { + /** Default bandwidth limit for SCP transfert in Kbit/s (-1 means unlimited) */ + private static final int DEFAULT_BANDWIDTH_LIMIT = -1; + private final SessionFactory sessionFactory; + private int bandwidthLimit; public SCPFileTransfer(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; + this.bandwidthLimit = DEFAULT_BANDWIDTH_LIMIT; } public SCPDownloadClient newSCPDownloadClient() { - return new SCPDownloadClient(newSCPEngine()); + return new SCPDownloadClient(newSCPEngine(), bandwidthLimit); } public SCPUploadClient newSCPUploadClient() { - return new SCPUploadClient(newSCPEngine()); + return new SCPUploadClient(newSCPEngine(), bandwidthLimit); } private SCPEngine newSCPEngine() { @@ -70,4 +75,10 @@ public void upload(LocalSourceFile localFile, String remotePath) newSCPUploadClient().copy(localFile, remotePath); } + public SCPFileTransfer bandwidthLimit(int limit) { + if (limit > 0) { + this.bandwidthLimit = limit; + } + return this; + } } diff --git a/src/main/java/net/schmizz/sshj/xfer/scp/SCPUploadClient.java b/src/main/java/net/schmizz/sshj/xfer/scp/SCPUploadClient.java index 474ce1fc1..ba5c8073b 100644 --- a/src/main/java/net/schmizz/sshj/xfer/scp/SCPUploadClient.java +++ b/src/main/java/net/schmizz/sshj/xfer/scp/SCPUploadClient.java @@ -24,17 +24,21 @@ import java.io.IOException; import java.io.InputStream; -import java.util.LinkedList; import java.util.List; +import static net.schmizz.sshj.xfer.scp.SCPEngine.SCPArguments; + /** Support for uploading files over a connected link using SCP. */ -public final class SCPUploadClient { +public final class SCPUploadClient extends AbstractSCPClient { - private final SCPEngine engine; private LocalFileFilter uploadFilter; SCPUploadClient(SCPEngine engine) { - this.engine = engine; + super(engine); + } + + SCPUploadClient(SCPEngine engine, int bandwidthLimit) { + super(engine, bandwidthLimit); } /** Upload a local file from {@code localFile} to {@code targetPath} on the remote host. */ @@ -55,11 +59,11 @@ public void setUploadFilter(LocalFileFilter uploadFilter) { private synchronized void startCopy(LocalSourceFile sourceFile, String targetPath) throws IOException { - List args = new LinkedList(); - args.add(Arg.SINK); - args.add(Arg.RECURSIVE); - if (sourceFile.providesAtimeMtime()) - args.add(Arg.PRESERVE_TIMES); + List args = SCPArguments.with(Arg.SINK) + .and(Arg.RECURSIVE) + .and(Arg.PRESERVE_TIMES, sourceFile.providesAtimeMtime()) + .and(Arg.LIMIT, String.valueOf(bandwidthLimit), (bandwidthLimit > 0)) + .arguments(); engine.execSCPWith(args, targetPath); engine.check("Start status OK"); process(engine.getTransferListener(), sourceFile); diff --git a/src/test/java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java b/src/test/java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java new file mode 100644 index 000000000..759266e64 --- /dev/null +++ b/src/test/java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java @@ -0,0 +1,82 @@ +package net.schmizz.sshj.xfer.scp; + +import com.hierynomus.sshj.test.SshFixture; +import com.hierynomus.sshj.test.util.FileUtil; +import net.schmizz.sshj.SSHClient; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.io.IOException; + +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; + +public class SCPFileTransferTest { + + public static final String DEFAULT_FILE_NAME = "my_file.txt"; + File targetDir; + File sourceFile; + File targetFile; + SSHClient sshClient; + + @Rule + public SshFixture fixture = new SshFixture(); + + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); + + @Before + public void init() throws IOException { + sourceFile = tempFolder.newFile(DEFAULT_FILE_NAME); + FileUtil.writeToFile(sourceFile, "This is my file"); + targetDir = tempFolder.newFolder(); + targetFile = new File(targetDir + File.separator + DEFAULT_FILE_NAME); + sshClient = fixture.setupConnectedDefaultClient(); + sshClient.authPassword("test", "test"); + } + + @After + public void cleanup() { + if (targetFile.exists()) { + targetFile.delete(); + } + } + + @Test + public void should_SCP_Upload_File() throws IOException { + SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer(); + assertFalse(targetFile.exists()); + scpFileTransfer.upload(sourceFile.getAbsolutePath(), targetDir.getAbsolutePath()); + assertTrue(targetFile.exists()); + } + + @Test + public void should_SCP_Upload_File_With_Bandwidth_Limit() throws IOException { + // Limit upload transfert at 2Mo/s + SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer().bandwidthLimit(16000); + assertFalse(targetFile.exists()); + scpFileTransfer.upload(sourceFile.getAbsolutePath(), targetDir.getAbsolutePath()); + assertTrue(targetFile.exists()); + } + + @Test + public void should_SCP_Download_File() throws IOException { + SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer(); + assertFalse(targetFile.exists()); + scpFileTransfer.download(sourceFile.getAbsolutePath(), targetDir.getAbsolutePath()); + assertTrue(targetFile.exists()); + } + + @Test + public void should_SCP_Download_File_With_Bandwidth_Limit() throws IOException { + // Limit download transfert at 128Ko/s + SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer().bandwidthLimit(1024); + assertFalse(targetFile.exists()); + scpFileTransfer.download(sourceFile.getAbsolutePath(), targetDir.getAbsolutePath()); + assertTrue(targetFile.exists()); + } +} From e81fdb8d8bbb626b550a2ffe814d78c2984da6f1 Mon Sep 17 00:00:00 2001 From: lguerin Date: Thu, 13 Aug 2015 09:36:02 +0200 Subject: [PATCH 2/6] Verbose failed tests --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index 26bce92b4..6d0338917 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,9 @@ configurations { } test { + testLogging { + exceptionFormat = 'full' + } include "**/*Test.*" if (!project.hasProperty("allTests")) { useJUnit { From dec00efcaa2bf1b037066defdd13f43c3ec07eb0 Mon Sep 17 00:00:00 2001 From: lguerin Date: Thu, 13 Aug 2015 10:49:56 +0200 Subject: [PATCH 3/6] Fix typo and clarify rate transfer comment --- src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java b/src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java index a71371c87..c25cdde6b 100644 --- a/src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java +++ b/src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java @@ -28,7 +28,7 @@ public class SCPFileTransfer extends AbstractFileTransfer implements FileTransfer { - /** Default bandwidth limit for SCP transfert in Kbit/s (-1 means unlimited) */ + /** Default bandwidth limit for SCP transfer in kilobit/s (-1 means unlimited) */ private static final int DEFAULT_BANDWIDTH_LIMIT = -1; private final SessionFactory sessionFactory; From 9c424f94316cdf8203a23b8c5b1d7b22237d4bef Mon Sep 17 00:00:00 2001 From: lguerin Date: Thu, 13 Aug 2015 11:37:15 +0200 Subject: [PATCH 4/6] Remove underscores from Test method's name --- .../net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java b/src/test/java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java index 759266e64..d62471fa1 100644 --- a/src/test/java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java +++ b/src/test/java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java @@ -47,7 +47,7 @@ public void cleanup() { } @Test - public void should_SCP_Upload_File() throws IOException { + public void shouldSCPUpload_File() throws IOException { SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer(); assertFalse(targetFile.exists()); scpFileTransfer.upload(sourceFile.getAbsolutePath(), targetDir.getAbsolutePath()); @@ -55,7 +55,7 @@ public void should_SCP_Upload_File() throws IOException { } @Test - public void should_SCP_Upload_File_With_Bandwidth_Limit() throws IOException { + public void shouldSCPUploadFileWithBandwidthLimit() throws IOException { // Limit upload transfert at 2Mo/s SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer().bandwidthLimit(16000); assertFalse(targetFile.exists()); @@ -64,7 +64,7 @@ public void should_SCP_Upload_File_With_Bandwidth_Limit() throws IOException { } @Test - public void should_SCP_Download_File() throws IOException { + public void shouldSCPDownloadFile() throws IOException { SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer(); assertFalse(targetFile.exists()); scpFileTransfer.download(sourceFile.getAbsolutePath(), targetDir.getAbsolutePath()); @@ -72,7 +72,7 @@ public void should_SCP_Download_File() throws IOException { } @Test - public void should_SCP_Download_File_With_Bandwidth_Limit() throws IOException { + public void shouldSCPDownloadFileWithBandwidthLimit() throws IOException { // Limit download transfert at 128Ko/s SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer().bandwidthLimit(1024); assertFalse(targetFile.exists()); From 84990ada08d58cfd695b220f5dc748aedaa687a1 Mon Sep 17 00:00:00 2001 From: lguerin Date: Thu, 13 Aug 2015 14:41:09 +0200 Subject: [PATCH 5/6] Fix typo --- .../java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java b/src/test/java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java index d62471fa1..d7a8d466b 100644 --- a/src/test/java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java +++ b/src/test/java/net/schmizz/sshj/xfer/scp/SCPFileTransferTest.java @@ -47,7 +47,7 @@ public void cleanup() { } @Test - public void shouldSCPUpload_File() throws IOException { + public void shouldSCPUploadFile() throws IOException { SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer(); assertFalse(targetFile.exists()); scpFileTransfer.upload(sourceFile.getAbsolutePath(), targetDir.getAbsolutePath()); @@ -56,7 +56,7 @@ public void shouldSCPUpload_File() throws IOException { @Test public void shouldSCPUploadFileWithBandwidthLimit() throws IOException { - // Limit upload transfert at 2Mo/s + // Limit upload transfer at 2Mo/s SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer().bandwidthLimit(16000); assertFalse(targetFile.exists()); scpFileTransfer.upload(sourceFile.getAbsolutePath(), targetDir.getAbsolutePath()); @@ -73,7 +73,7 @@ public void shouldSCPDownloadFile() throws IOException { @Test public void shouldSCPDownloadFileWithBandwidthLimit() throws IOException { - // Limit download transfert at 128Ko/s + // Limit download transfer at 128Ko/s SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer().bandwidthLimit(1024); assertFalse(targetFile.exists()); scpFileTransfer.download(sourceFile.getAbsolutePath(), targetDir.getAbsolutePath()); From d18e9d996162d880db8f16f3a2e9c16622bf2f5b Mon Sep 17 00:00:00 2001 From: lguerin Date: Thu, 13 Aug 2015 14:44:45 +0200 Subject: [PATCH 6/6] Refactor SCP arguments --- .../sshj/xfer/scp/SCPDownloadClient.java | 3 +- .../net/schmizz/sshj/xfer/scp/SCPEngine.java | 90 ++++++++++--------- .../sshj/xfer/scp/SCPUploadClient.java | 3 +- 3 files changed, 53 insertions(+), 43 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 7d80c5e20..4c35513d8 100644 --- a/src/main/java/net/schmizz/sshj/xfer/scp/SCPDownloadClient.java +++ b/src/main/java/net/schmizz/sshj/xfer/scp/SCPDownloadClient.java @@ -26,6 +26,7 @@ import java.util.Arrays; import java.util.List; +import static net.schmizz.sshj.xfer.scp.SCPEngine.SCPArgument; import static net.schmizz.sshj.xfer.scp.SCPEngine.SCPArguments; /** Support for uploading files over a connected link using SCP. */ @@ -63,7 +64,7 @@ public void setRecursiveMode(boolean recursive) { void startCopy(String sourcePath, LocalDestFile targetFile) throws IOException { - List args = SCPArguments.with(Arg.SOURCE) + List args = SCPArguments.with(Arg.SOURCE) .and(Arg.QUIET) .and(Arg.PRESERVE_TIMES) .and(Arg.RECURSIVE, recursiveMode) diff --git a/src/main/java/net/schmizz/sshj/xfer/scp/SCPEngine.java b/src/main/java/net/schmizz/sshj/xfer/scp/SCPEngine.java index 78d7eff69..321ec943e 100644 --- a/src/main/java/net/schmizz/sshj/xfer/scp/SCPEngine.java +++ b/src/main/java/net/schmizz/sshj/xfer/scp/SCPEngine.java @@ -41,30 +41,17 @@ enum Arg { VERBOSE('v'), PRESERVE_TIMES('p'), QUIET('q'), - LIMIT('l', ""); + LIMIT('l'); private final char a; - private String v; private Arg(char a) { this.a = a; } - private Arg(char a, String v) { - this.a = a; - this.v = v; - } - - public void setValue(String v) { - this.v = v; - } @Override public String toString() { - String arg = "-" + a; - if (v != null && v.length() > 0) { - arg = arg + v; - } - return arg; + return "-" + a; } } @@ -112,10 +99,10 @@ void cleanSlate() { exitStatus = -1; } - void execSCPWith(List args, String path) + void execSCPWith(List args, String path) throws SSHException { final StringBuilder cmd = new StringBuilder(SCP_COMMAND); - for (Arg arg : args) { + for (SCPArgument arg : args) { cmd.append(" ").append(arg); } cmd.append(" "); @@ -201,62 +188,83 @@ TransferListener getTransferListener() { return listener; } + public static class SCPArgument { + + private Arg name; + private String value; + + private SCPArgument(Arg name, String value) { + this.name = name; + this.value = value; + } + + public static SCPArgument addArgument(Arg name, String value) { + return new SCPArgument(name, value); + } + + @Override + public String toString() { + String option = name.toString(); + if (value != null) { + option = option + value; + } + return option; + } + } + public static class SCPArguments { - private static List args = null; + private static List args = null; private SCPArguments() { - this.args = new LinkedList(); + this.args = new LinkedList(); } - private static void addArg(Arg arg, String value, boolean accept) { + private static void addArgument(Arg name, String value, boolean accept) { if (accept) { - if (null != value && value.length() > 0) { - arg.setValue(value); - } - args.add(arg); + args.add(SCPArgument.addArgument(name, value)); } } - public static SCPArguments with(Arg arg) { - return with(arg, null, true); + public static SCPArguments with(Arg name) { + return with(name, null, true); } - public static SCPArguments with(Arg arg, String value) { - return with(arg, value, true); + public static SCPArguments with(Arg name, String value) { + return with(name, value, true); } - public static SCPArguments with(Arg arg, boolean accept) { - return with(arg, null, accept); + public static SCPArguments with(Arg name, boolean accept) { + return with(name, null, accept); } - public static SCPArguments with(Arg arg, String value, boolean accept) { + public static SCPArguments with(Arg name, String value, boolean accept) { SCPArguments scpArguments = new SCPArguments(); - addArg(arg, value, accept); + addArgument(name, value, accept); return scpArguments; } - public SCPArguments and(Arg arg) { - addArg(arg, null, true); + public SCPArguments and(Arg name) { + addArgument(name, null, true); return this; } - public SCPArguments and(Arg arg, String value) { - addArg(arg, value, true); + public SCPArguments and(Arg name, String value) { + addArgument(name, value, true); return this; } - public SCPArguments and(Arg arg, boolean accept) { - addArg(arg, null, accept); + public SCPArguments and(Arg name, boolean accept) { + addArgument(name, null, accept); return this; } - public SCPArguments and(Arg arg, String value, boolean accept) { - addArg(arg, value, accept); + public SCPArguments and(Arg name, String value, boolean accept) { + addArgument(name, value, accept); return this; } - public List arguments() { + public List arguments() { return args; } } diff --git a/src/main/java/net/schmizz/sshj/xfer/scp/SCPUploadClient.java b/src/main/java/net/schmizz/sshj/xfer/scp/SCPUploadClient.java index ba5c8073b..58fa3257c 100644 --- a/src/main/java/net/schmizz/sshj/xfer/scp/SCPUploadClient.java +++ b/src/main/java/net/schmizz/sshj/xfer/scp/SCPUploadClient.java @@ -26,6 +26,7 @@ import java.io.InputStream; import java.util.List; +import static net.schmizz.sshj.xfer.scp.SCPEngine.SCPArgument; import static net.schmizz.sshj.xfer.scp.SCPEngine.SCPArguments; /** Support for uploading files over a connected link using SCP. */ @@ -59,7 +60,7 @@ public void setUploadFilter(LocalFileFilter uploadFilter) { private synchronized void startCopy(LocalSourceFile sourceFile, String targetPath) throws IOException { - List args = SCPArguments.with(Arg.SINK) + List args = SCPArguments.with(Arg.SINK) .and(Arg.RECURSIVE) .and(Arg.PRESERVE_TIMES, sourceFile.providesAtimeMtime()) .and(Arg.LIMIT, String.valueOf(bandwidthLimit), (bandwidthLimit > 0))