Search in sources :

Example 1 with SshException

use of com.jn.agileway.ssh.client.SshException 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;
}
Also used : LocalPortForwarder(com.trilead.ssh2.LocalPortForwarder) InetSocketAddress(java.net.InetSocketAddress) Connection(com.trilead.ssh2.Connection) ForwardingChannelInfo(com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo) SshException(com.jn.agileway.ssh.client.SshException)

Example 2 with SshException

use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.

the class SshCommandLineLauncher method exec.

@Override
public SshCommandExecutionAdaptor exec(CommandLine commandLine, Map<String, String> environmentVariables, File workingDirectory) throws IOException {
    try {
        if (!connection.isConnected()) {
            throw new SshException(new IllegalStateException("connection is not connected"));
        }
        final SessionedChannel sessionChannel = connection.openSession();
        Preconditions.checkNotNull(sessionChannel, "the ssh exec session channel is null");
        String command = commandLine.getCommandLineString();
        if (workingDirectory != null) {
            String path = workingDirectory.getPath();
            path = path.replace("\\", "/");
            command = "cd " + path + ";" + command;
        }
        if (Emptys.isNotEmpty(environmentVariables)) {
            String envs = null;
            if (environmentSettingsSupplier != null) {
                envs = environmentSettingsSupplier.get(environmentVariables);
            }
            if (Strings.isNotEmpty(envs)) {
                command = envs + command;
            } else {
                Collects.forEach(environmentVariables, new Consumer2<String, String>() {

                    @Override
                    public void accept(String variable, String value) {
                        sessionChannel.env(variable, value);
                    }
                });
            }
        }
        sessionChannel.exec(command);
        return new SshCommandExecutionAdaptor(sessionChannel);
    } catch (Throwable ex) {
        throw Throwables.wrapAsRuntimeException(ex);
    }
}
Also used : SessionedChannel(com.jn.agileway.ssh.client.channel.SessionedChannel) SshException(com.jn.agileway.ssh.client.SshException)

Example 3 with SshException

use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.

the class SshjSessionedChannel method signal.

@Override
public void signal(Signal signal) throws SshException {
    Preconditions.checkNotEmpty(signal, "the signal is null or empty");
    Preconditions.checkArgument(signal != Signal.UNKNOWN, "the signal is UNKNOWN");
    net.schmizz.sshj.connection.channel.direct.Signal sg = null;
    String name = signal.name();
    sg = net.schmizz.sshj.connection.channel.direct.Signal.fromString(name);
    try {
        if (this.shell != null) {
            this.shell.signal(sg);
        }
        if (this.command != null) {
            this.command.signal(sg);
        }
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
}
Also used : SshException(com.jn.agileway.ssh.client.SshException)

Example 4 with SshException

use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.

the class SshjSessionedChannel method internalShell.

@Override
protected void internalShell() throws SshException {
    try {
        this.shell = this.session.startShell();
        initStreams();
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
}
Also used : SshException(com.jn.agileway.ssh.client.SshException)

Example 5 with SshException

use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.

the class SshjSessionedChannel method internalExec.

@Override
protected void internalExec(String command) throws SshException {
    Preconditions.checkNotEmpty(command, "the command is illegal : {}", command);
    try {
        this.command = this.session.exec(command);
        initStreams();
    } 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