use of com.jn.agileway.ssh.client.SshException 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.SshException in project agileway by fangjinuo.
the class J2sshForwardingClient method stopRemoteForwarding.
@Override
public void stopRemoteForwarding(ForwardingChannelInfo channel) throws SshException {
SshClient sshClient = this.connection.getDelegate();
com.sshtools.j2ssh.forwarding.ForwardingClient delegate = sshClient.getForwardingClient();
try {
delegate.stopRemoteForwarding(ForwardingChannelInfo.id(channel));
} catch (Throwable ex) {
throw new SshException(ex);
}
}
use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.
the class J2sshForwardingClient method stopLocalForwarding.
@Override
public void stopLocalForwarding(ForwardingChannelInfo channel) throws SshException {
SshClient sshClient = this.connection.getDelegate();
com.sshtools.j2ssh.forwarding.ForwardingClient delegate = sshClient.getForwardingClient();
try {
delegate.stopLocalForwarding(ForwardingChannelInfo.id(channel));
} catch (Throwable ex) {
throw new SshException(ex);
}
}
use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.
the class JschSessionedChannel method internalSubsystem.
@Override
protected void internalSubsystem(String subsystem) throws SshException {
Preconditions.checkNotEmpty(subsystem, "the subsystem is illegal : {}", subsystem);
Preconditions.checkState(session != null && session.isConnected(), "the session is not connected");
try {
this.type = JschChannelType.SUBSYSTEM;
ChannelSubsystem channel = (ChannelSubsystem) session.openChannel(type.getName());
channel.setSubsystem(subsystem);
this.channel = channel;
startChannel();
} catch (Throwable ex) {
throw new SshException(ex);
}
}
use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.
the class JschSessionedChannel method internalShell.
@Override
protected void internalShell() throws SshException {
Preconditions.checkState(session != null && session.isConnected(), "the session is not connected");
try {
this.type = JschChannelType.SHELL;
this.channel = session.openChannel(type.getName());
startChannel();
} catch (Throwable ex) {
throw new SshException(ex);
}
}
Aggregations