Skip to content
Snippets Groups Projects
Commit c08feda1 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

add forward support

parent 26f24b7f
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,8 @@ import com.jcraft.jsch.JSchException; ...@@ -8,6 +8,8 @@ import com.jcraft.jsch.JSchException;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -35,8 +37,8 @@ public class SshCommandClient extends AbstractBaseSshClient { ...@@ -35,8 +37,8 @@ public class SshCommandClient extends AbstractBaseSshClient {
super(hostName, userName, keyFile, pass); super(hostName, userName, keyFile, pass);
} }
public String executeCommand(String command) { public List<String> executeCommand(String command) {
StringBuilder sb = new StringBuilder(); List<String> result = new LinkedList<>();
try { try {
ChannelExec channelExec = (ChannelExec) getConnectedSession().openChannel( ChannelExec channelExec = (ChannelExec) getConnectedSession().openChannel(
"exec"); "exec");
...@@ -50,7 +52,7 @@ public class SshCommandClient extends AbstractBaseSshClient { ...@@ -50,7 +52,7 @@ public class SshCommandClient extends AbstractBaseSshClient {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
sb.append(line).append('\n'); result.add(line);
} }
int exitStatus = channelExec.getExitStatus(); int exitStatus = channelExec.getExitStatus();
...@@ -70,6 +72,17 @@ public class SshCommandClient extends AbstractBaseSshClient { ...@@ -70,6 +72,17 @@ public class SshCommandClient extends AbstractBaseSshClient {
log.error("Error: ", e); log.error("Error: ", e);
throw new RuntimeException(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;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment