|
Setting up an SSH tunnel |
|
You may create an SSH tunnel by creating a new SshTunneler instance, providing local port to listen on, parameters of SSH service and remote IP and port to tunnel data to.
Example
The following example demonstrates creating a secure tunnel for a POP3 email service.
// define local port to listen on
int localPort = 110;
// define SSH connection parameters
SshParameters params = new SshParameters("ssh.mydomain.com","sshusername","sshpassword");
// define remote port and IP of POP3 service.
String remoteIP = "pop3.mydomain.com";
int remotePort = 110;
// create tunnel
SshTunneler tunneler = new SshTunneler(localPort, params, remoteIP, remotePort);
// start listening on local port
tunneler.start();
// stop listening on local port after finished
tunneler.stop();