Example usage for org.apache.commons.net.ssh SSHClient newLocalPortForwarder

List of usage examples for org.apache.commons.net.ssh SSHClient newLocalPortForwarder

Introduction

In this page you can find the example usage for org.apache.commons.net.ssh SSHClient newLocalPortForwarder.

Prototype

public LocalPortForwarder newLocalPortForwarder(SocketAddress address, String host, int port)
        throws IOException 

Source Link

Document

Create a LocalPortForwarder that will listen on address and forward incoming connections to the server; which will further forward them to host:port .

Usage

From source file:examples.ssh.LocalPF.java

public static void main(String... args) throws Exception {
    SSHClient ssh = new SSHClient();

    ssh.loadKnownHosts();/*from ww  w .j  a v a 2 s .c  om*/

    ssh.connect("localhost");
    try {

        ssh.authPublickey(System.getProperty("user.name"));

        /*
         * _We_ listen on localhost:8080 and forward all connections on to server, which then forwards it to
         * google.com:80
         */

        ssh.newLocalPortForwarder(new InetSocketAddress("localhost", 8080), "google.com", 80).listen();

    } finally {
        ssh.disconnect();
    }
}