Search in sources :

Example 16 with SshException

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);
    }
}
Also used : ToSsh2HostKeyVerifierAdapter(com.jn.agileway.ssh.client.impl.trileadssh2.verifier.ToSsh2HostKeyVerifierAdapter) AbstractSshConnection(com.jn.agileway.ssh.client.AbstractSshConnection) Connection(com.trilead.ssh2.Connection) SshException(com.jn.agileway.ssh.client.SshException)

Example 17 with SshException

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);
    }
}
Also used : SshException(com.jn.agileway.ssh.client.SshException) SftpSession(com.jn.agileway.ssh.client.sftp.SftpSession) Session(com.trilead.ssh2.Session) Ssh2SftpSession(com.jn.agileway.ssh.client.impl.trileadssh2.sftp.Ssh2SftpSession)

Example 18 with SshException

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);
    }
}
Also used : SshException(com.jn.agileway.ssh.client.SshException) ToSshjHostKeyVerifierAdapter(com.jn.agileway.ssh.client.impl.sshj.verifier.ToSshjHostKeyVerifierAdapter)

Example 19 with SshException

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);
}
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 20 with SshException

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);
    }
}
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)40 ForwardingChannelInfo (com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo)7 RequestFuture (com.sshtools.common.ssh.RequestFuture)4 SshClient (com.sshtools.j2ssh.SshClient)4 Connection (com.trilead.ssh2.Connection)3 InetSocketAddress (java.net.InetSocketAddress)3 SSHClient (net.schmizz.sshj.SSHClient)3 AbstractSshConnection (com.jn.agileway.ssh.client.AbstractSshConnection)2 Ssh2SftpSession (com.jn.agileway.ssh.client.impl.ganymedssh2.sftp.Ssh2SftpSession)2 ToSynergyHostKeyVerifierAdapter (com.jn.agileway.ssh.client.impl.synergy.verifier.ToSynergyHostKeyVerifierAdapter)2 Ssh2SftpSession (com.jn.agileway.ssh.client.impl.trileadssh2.sftp.Ssh2SftpSession)2 SftpSession (com.jn.agileway.ssh.client.sftp.SftpSession)2 SshClient (com.sshtools.client.SshClient)2 SshClientContext (com.sshtools.client.SshClientContext)2 RemotePortForwarder (net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder)2 Connection (ch.ethz.ssh2.Connection)1 LocalPortForwarder (ch.ethz.ssh2.LocalPortForwarder)1 SFTPv3Client (ch.ethz.ssh2.SFTPv3Client)1 Session (ch.ethz.ssh2.Session)1 ChannelSftp (com.jcraft.jsch.ChannelSftp)1