Skip to content

Commit

Permalink
don't use a local fixed port for ssh tunnel. fixes #298
Browse files Browse the repository at this point in the history
  • Loading branch information
oakkitten committed Oct 18, 2016
1 parent c48b9bb commit 05a4472
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ public class SSHConnection extends AbstractConnection {
protected static Logger logger = LoggerFactory.getLogger("SSHConnection");

private Session sshSession;
private String sshPassword;

final static private int SSH_LOCAL_PORT = 22231;
private Socket sock;

private String sshPassword;
private String server;
private int port;

private Socket sock;

public SSHConnection(String server, int port, String sshHost, int sshPort, String sshUsername,
String sshPassword, byte[] sshKey, byte[] sshKnownHosts) throws JSchException {
this.server = server;
Expand All @@ -65,8 +62,8 @@ public SSHConnection(String server, int port, String sshHost, int sshPort, Strin
(ClosedByInterruptException) e.getCause() : e;
}

sshSession.setPortForwardingL(SSH_LOCAL_PORT, server, port);
sock = new Socket("127.0.0.1", SSH_LOCAL_PORT);
int localPort = sshSession.setPortForwardingL(0, server, port);
sock = new Socket("127.0.0.1", localPort);
out = sock.getOutputStream();
in = sock.getInputStream();
}
Expand Down

0 comments on commit 05a4472

Please sign in to comment.