From c08feda1abebb1a1e8916a9721b9983038fa5e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ko=C5=BEusznik?= <jan@kozusznik.cz> Date: Sun, 27 Jan 2019 21:22:47 +0100 Subject: [PATCH] add forward support --- .../it4i/fiji/scpclient/SshCommandClient.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/SshCommandClient.java b/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/SshCommandClient.java index 6b3ab613..78c54aee 100644 --- a/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/SshCommandClient.java +++ b/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/SshCommandClient.java @@ -8,6 +8,8 @@ import com.jcraft.jsch.JSchException; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.LinkedList; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,8 +37,8 @@ public class SshCommandClient extends AbstractBaseSshClient { super(hostName, userName, keyFile, pass); } - public String executeCommand(String command) { - StringBuilder sb = new StringBuilder(); + public List<String> executeCommand(String command) { + List<String> result = new LinkedList<>(); try { ChannelExec channelExec = (ChannelExec) getConnectedSession().openChannel( "exec"); @@ -50,7 +52,7 @@ public class SshCommandClient extends AbstractBaseSshClient { String line; while ((line = reader.readLine()) != null) { - sb.append(line).append('\n'); + result.add(line); } int exitStatus = channelExec.getExitStatus(); @@ -70,6 +72,17 @@ public class SshCommandClient extends AbstractBaseSshClient { log.error("Error: ", e); throw new RuntimeException(e); } - return sb.toString(); + return result; + } + + public boolean setPortForwarding(int lport, String rhost, int rport) { + try { + getConnectedSession().setPortForwardingL(lport, rhost, rport); + } + catch (JSchException exc) { + log.error("forward", exc); + return false; + } + return true; } } -- GitLab