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

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

Introduction

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

Prototype

public RemotePortForwarder getRemotePortForwarder() 

Source Link

Document

Returns a RemotePortForwarder that allows requesting remote forwarding over this connection.

Usage

From source file:examples.ssh.RemotePF.java

public static void main(String... args) throws Exception {
    SSHClient client = new SSHClient();
    client.loadKnownHosts();/*from   ww  w  . j av  a2 s . c o  m*/

    client.connect("localhost");
    try {

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

        /*
         * We make _server_ listen on port 8080, which forwards all connections to us as a channel, and we further
         * forward all such channels to google.com:80
         */
        client.getRemotePortForwarder().bind(new Forward(8080), //
                new SocketForwardingConnectListener(new InetSocketAddress("google.com", 80)));

        // Something to hang on to so forwarding stays
        client.getTransport().join();

    } finally {
        client.disconnect();
    }
}