use of com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo in project agileway by fangjinuo.
the class Ssh2ForwardingClient method startLocalForwarding.
@Override
public ForwardingChannelInfo startLocalForwarding(String bindToHost, int bindToPort, String destHost, int destPort) throws SshException {
ForwardingChannelInfo channel = new ForwardingChannelInfo(ForwardingChannelInfo.LOCAL_FORWARDING_CHANNEL, bindToHost, bindToPort, destHost, destPort);
if (!localForwarderMap.containsKey(ForwardingChannelInfo.id(channel))) {
Connection delegate = this.connection.getDelegate();
try {
LocalPortForwarder localPortForwarder = delegate.createLocalPortForwarder(new InetSocketAddress(bindToHost, bindToPort), destHost, destPort);
localForwarderMap.put(ForwardingChannelInfo.id(channel), localPortForwarder);
} catch (Throwable ex) {
throw new SshException(ex);
}
}
return channel;
}
use of com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo 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);
}
use of com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo in project agileway by fangjinuo.
the class SshjForwardingClient method startLocalForwarding.
@Override
public ForwardingChannelInfo startLocalForwarding(String bindToHost, int bindToPort, String destHost, int destPort) throws SshException {
SSHClient delegate = connection.getDelegate();
ForwardingChannelInfo channel = new ForwardingChannelInfo(ForwardingChannelInfo.LOCAL_FORWARDING_CHANNEL, bindToHost, bindToPort, destHost, destPort);
if (!localForwardingMap.containsKey(ForwardingChannelInfo.id(channel))) {
SocketAddress address = new InetSocketAddress(bindToHost, bindToPort);
try {
ServerSocket serverSocket = new ServerSocket();
serverSocket.bind(address);
Object parameters = Reflects.newInstance(LOCAL_PORT_FORWARDER_PARAMETERS, new Class[] { String.class, int.class, String.class, int.class }, bindToHost, bindToPort, destHost, destPort);
final LocalPortForwarder forwarder = Reflects.invoke(NEW_LOCAL_PORT_FORWARDER, delegate, new Object[] { parameters, serverSocket }, true, true);
Thread t = new Thread() {
@Override
public void run() {
try {
forwarder.listen();
} catch (Throwable ex) {
// ignore it , interrupted
}
}
};
t.start();
LocalForwardingChannelCtx ctx = new LocalForwardingChannelCtx();
ctx.thread = t;
ctx.channel = channel;
ctx.forwarder = forwarder;
localForwardingMap.put(ForwardingChannelInfo.id(channel), ctx);
} catch (Throwable ex) {
throw new SshException(ex);
}
}
return channel;
}
use of com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo in project agileway by fangjinuo.
the class Ssh2ForwardingClient method startLocalForwarding.
@Override
public ForwardingChannelInfo startLocalForwarding(String bindToHost, int bindToPort, String destHost, int destPort) throws SshException {
ForwardingChannelInfo channel = new ForwardingChannelInfo(ForwardingChannelInfo.LOCAL_FORWARDING_CHANNEL, bindToHost, bindToPort, destHost, destPort);
LocalPortForwarder forwarder = localForwarderMap.get(channel);
if (forwarder == null) {
try {
ch.ethz.ssh2.Connection delegate = this.connection.getDelegate();
forwarder = delegate.createLocalPortForwarder(bindToPort, destHost, destPort);
localForwarderMap.put(ForwardingChannelInfo.id(channel), forwarder);
} catch (Throwable ex) {
throw new SshException(ex);
}
}
return channel;
}
use of com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo in project agileway by fangjinuo.
the class J2sshForwardingClient method startLocalForwarding.
@Override
public ForwardingChannelInfo startLocalForwarding(String bindToHost, int bindToPort, String destHost, int destPort) throws SshException {
ForwardingChannelInfo channel = new ForwardingChannelInfo(ForwardingChannelInfo.LOCAL_FORWARDING_CHANNEL, bindToHost, bindToPort, destHost, destPort);
SshClient sshClient = this.connection.getDelegate();
com.sshtools.j2ssh.forwarding.ForwardingClient delegate = sshClient.getForwardingClient();
try {
if (!delegate.getLocalForwardings().containsKey(ForwardingChannelInfo.id(channel))) {
delegate.addLocalForwarding(ForwardingChannelInfo.id(channel), bindToHost, bindToPort, destHost, destPort);
}
delegate.startLocalForwarding(ForwardingChannelInfo.id(channel));
} catch (Throwable ex) {
throw new SshException(ex);
}
return channel;
}
Aggregations