Search in sources :

Example 6 with ForwardingChannelInfo

use of com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo in project agileway by fangjinuo.

the class J2sshForwardingClient method startRemoteForwarding.

@Override
public ForwardingChannelInfo startRemoteForwarding(String bindToHost, int bindToPort, String destHost, int destPort) throws SshException {
    ForwardingChannelInfo channel = new ForwardingChannelInfo(ForwardingChannelInfo.REMOTE_FORWARDING_CHANNEL, bindToHost, bindToPort, destHost, destPort);
    SshClient sshClient = this.connection.getDelegate();
    com.sshtools.j2ssh.forwarding.ForwardingClient delegate = sshClient.getForwardingClient();
    try {
        if (!delegate.getRemoteForwardings().containsKey(ForwardingChannelInfo.id(channel))) {
            delegate.addRemoteForwarding(ForwardingChannelInfo.id(channel), bindToHost, bindToPort, destHost, destPort);
        }
        delegate.startRemoteForwarding(ForwardingChannelInfo.id(channel));
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
    return channel;
}
Also used : SshClient(com.sshtools.j2ssh.SshClient) ForwardingChannelInfo(com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo) SshException(com.jn.agileway.ssh.client.SshException)

Example 7 with ForwardingChannelInfo

use of com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo in project agileway by fangjinuo.

the class Ssh2ForwardingClient method startRemoteForwarding.

@Override
public ForwardingChannelInfo startRemoteForwarding(String bindToHost, int bindToPort, String destHost, int destPort) throws SshException {
    Connection delegate = this.connection.getDelegate();
    ForwardingChannelInfo channel = new ForwardingChannelInfo(ForwardingChannelInfo.REMOTE_FORWARDING_CHANNEL, bindToHost, bindToPort, destHost, destPort);
    try {
        delegate.requestRemotePortForwarding(bindToHost, bindToPort, destHost, destPort);
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
    return channel;
}
Also used : Connection(com.trilead.ssh2.Connection) ForwardingChannelInfo(com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo) SshException(com.jn.agileway.ssh.client.SshException)

Aggregations

SshException (com.jn.agileway.ssh.client.SshException)7 ForwardingChannelInfo (com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo)7 InetSocketAddress (java.net.InetSocketAddress)3 SshClient (com.sshtools.j2ssh.SshClient)2 Connection (com.trilead.ssh2.Connection)2 SSHClient (net.schmizz.sshj.SSHClient)2 LocalPortForwarder (ch.ethz.ssh2.LocalPortForwarder)1 LocalPortForwarder (com.trilead.ssh2.LocalPortForwarder)1 ServerSocket (java.net.ServerSocket)1 SocketAddress (java.net.SocketAddress)1 LocalPortForwarder (net.schmizz.sshj.connection.channel.direct.LocalPortForwarder)1 RemotePortForwarder (net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder)1 SocketForwardingConnectListener (net.schmizz.sshj.connection.channel.forwarded.SocketForwardingConnectListener)1