Search in sources :

Example 21 with SshException

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;
}
Also used : LocalPortForwarder(net.schmizz.sshj.connection.channel.direct.LocalPortForwarder) InetSocketAddress(java.net.InetSocketAddress) SSHClient(net.schmizz.sshj.SSHClient) ServerSocket(java.net.ServerSocket) ForwardingChannelInfo(com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo) SshException(com.jn.agileway.ssh.client.SshException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 22 with SshException

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);
    }
}
Also used : SshClient(com.sshtools.j2ssh.SshClient) SshException(com.jn.agileway.ssh.client.SshException)

Example 23 with SshException

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);
    }
}
Also used : SshClient(com.sshtools.j2ssh.SshClient) SshException(com.jn.agileway.ssh.client.SshException)

Example 24 with SshException

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

Example 25 with SshException

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

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