Search in sources :

Example 1 with RemotePortForwarder

use of net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder in project agileway by fangjinuo.

the class SshjForwardingClient method startRemoteForwarding.

@Override
public ForwardingChannelInfo startRemoteForwarding(String bindToHost, int bindToPort, String destHost, int destPort) throws SshException {
    SSHClient delegate = connection.getDelegate();
    RemotePortForwarder forwarder = delegate.getRemotePortForwarder();
    RemotePortForwarder.Forward forward = new RemotePortForwarder.Forward(bindToHost, bindToPort);
    try {
        forwarder.bind(forward, new SocketForwardingConnectListener(new InetSocketAddress(bindToHost, bindToPort)));
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
    return new ForwardingChannelInfo(ForwardingChannelInfo.REMOTE_FORWARDING_CHANNEL, bindToHost, bindToPort, destHost, destPort);
}
Also used : SocketForwardingConnectListener(net.schmizz.sshj.connection.channel.forwarded.SocketForwardingConnectListener) InetSocketAddress(java.net.InetSocketAddress) SSHClient(net.schmizz.sshj.SSHClient) SshException(com.jn.agileway.ssh.client.SshException) ForwardingChannelInfo(com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo) RemotePortForwarder(net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder)

Example 2 with RemotePortForwarder

use of net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder in project agileway by fangjinuo.

the class SshjForwardingClient method stopRemoteForwarding.

@Override
public void stopRemoteForwarding(ForwardingChannelInfo channel) throws SshException {
    SSHClient delegate = connection.getDelegate();
    RemotePortForwarder forwarder = delegate.getRemotePortForwarder();
    RemotePortForwarder.Forward forward = new RemotePortForwarder.Forward(channel.getBindingHost(), channel.getBindingPort());
    try {
        forwarder.cancel(forward);
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
}
Also used : SSHClient(net.schmizz.sshj.SSHClient) SshException(com.jn.agileway.ssh.client.SshException) RemotePortForwarder(net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder)

Aggregations

SshException (com.jn.agileway.ssh.client.SshException)2 SSHClient (net.schmizz.sshj.SSHClient)2 RemotePortForwarder (net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder)2 ForwardingChannelInfo (com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketForwardingConnectListener (net.schmizz.sshj.connection.channel.forwarded.SocketForwardingConnectListener)1