use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.
the class Ssh2Connection method connect.
@Override
public void connect(InetAddress host, int port, InetAddress localAddr, int localPort) throws SshException {
try {
if (delegate == null) {
Connection conn = new Connection(host.getHostName(), port);
if (this.hostKeyVerifier.isEmpty()) {
conn.connect();
} else {
conn.connect(new ToSsh2HostKeyVerifierAdapter(this.hostKeyVerifier));
}
setStatus(SshConnectionStatus.CONNECTED);
this.delegate = conn;
}
} catch (Throwable ex) {
throw new SshException(ex);
}
}
use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.
the class Ssh2Connection method openSession.
@Override
public SessionedChannel openSession() throws SshException {
Preconditions.checkNotNull(delegate);
Preconditions.checkState(getStatus() == SshConnectionStatus.CONNECTED, "ssh not connected");
try {
Session session = delegate.openSession();
Ssh2SessionedChannel channel = new Ssh2SessionedChannel(session);
return channel;
} catch (Throwable ex) {
throw new SshException(ex);
}
}
use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.
the class SshjConnection method connect.
@Override
public void connect(InetAddress host, int port, InetAddress localAddr, int localPort) throws SshException {
try {
makeSureSshClient();
if (!sshClient.isConnected()) {
if (!this.hostKeyVerifier.isEmpty()) {
sshClient.addHostKeyVerifier(new ToSshjHostKeyVerifierAdapter(this.hostKeyVerifier));
}
if (localAddr == null || !Nets.isValidPort(localPort)) {
sshClient.connect(host, port);
} else {
sshClient.connect(host, port, localAddr, localPort);
}
}
setStatus(SshConnectionStatus.CONNECTED);
} catch (Throwable ex) {
throw new SshException(ex);
}
}
use of com.jn.agileway.ssh.client.SshException 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.SshException 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);
}
}
Aggregations