Search in sources :

Example 6 with SshException

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

the class SshjSessionedChannel method internalSubsystem.

@Override
protected void internalSubsystem(String subsystem) throws SshException {
    Preconditions.checkNotEmpty(subsystem, "the subsystem is illegal : {}", subsystem);
    try {
        this.subsystem = this.session.startSubsystem(subsystem);
        initStreams();
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
}
Also used : SshException(com.jn.agileway.ssh.client.SshException)

Example 7 with SshException

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

the class SshjSessionedChannel method pty.

@Override
public void pty(String term, int termWidthCharacters, int termHeightCharacters, int termWidthPixels, int termHeightPixels, Map<PTYMode, Integer> terminalModes) throws SshException {
    final Map<net.schmizz.sshj.connection.channel.direct.PTYMode, Integer> terminalModeMap = new HashMap<net.schmizz.sshj.connection.channel.direct.PTYMode, Integer>();
    Collects.forEach(terminalModes, new Consumer2<PTYMode, Integer>() {

        @Override
        public void accept(PTYMode ptyMode, Integer value) {
            String operateName = ptyMode.name();
            net.schmizz.sshj.connection.channel.direct.PTYMode mode = Enums.ofName(net.schmizz.sshj.connection.channel.direct.PTYMode.class, operateName);
            if (mode != null) {
                terminalModeMap.put(mode, value);
            }
        }
    });
    try {
        this.session.allocatePTY(term, termWidthCharacters, termHeightCharacters, termWidthPixels, termHeightPixels, terminalModeMap);
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
}
Also used : HashMap(java.util.HashMap) SshException(com.jn.agileway.ssh.client.SshException) PTYMode(com.jn.agileway.ssh.client.utils.PTYMode)

Example 8 with SshException

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

the class SynergyConnection method authenticateWithPublicKey.

@Override
public boolean authenticateWithPublicKey(String user, byte[] pemPrivateKey, String passphrase) throws SshException {
    try {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(pemPrivateKey);
        SshKeyPair keyPair = SshKeyUtils.getPrivateKey(inputStream, passphrase);
        SshClientContext context = new SshClientContext();
        context.setUsername(user);
        context.setHostKeyVerification(new ToSynergyHostKeyVerifierAdapter(this.hostKeyVerifier));
        client = new SshClient(sshConfig.getHost(), sshConfig.getPort(), user, context, keyPair);
        if (client.isConnected()) {
            setStatus(SshConnectionStatus.CONNECTED);
        }
        return true;
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
}
Also used : SshKeyPair(com.sshtools.common.ssh.components.SshKeyPair) SshClientContext(com.sshtools.client.SshClientContext) ToSynergyHostKeyVerifierAdapter(com.jn.agileway.ssh.client.impl.synergy.verifier.ToSynergyHostKeyVerifierAdapter) SshClient(com.sshtools.client.SshClient) ByteArrayInputStream(java.io.ByteArrayInputStream) SshException(com.jn.agileway.ssh.client.SshException)

Example 9 with SshException

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

the class SynergyConnection method authenticateWithPassword.

@Override
public boolean authenticateWithPassword(String user, String password) throws SshException {
    try {
        SshClientContext context = new SshClientContext();
        context.setHostKeyVerification(new ToSynergyHostKeyVerifierAdapter(this.hostKeyVerifier));
        client = new SshClient(sshConfig.getHost(), sshConfig.getPort(), user, context, 30000L, password.toCharArray());
        if (client.isConnected()) {
            setStatus(SshConnectionStatus.CONNECTED);
        }
        return true;
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
}
Also used : SshClientContext(com.sshtools.client.SshClientContext) ToSynergyHostKeyVerifierAdapter(com.jn.agileway.ssh.client.impl.synergy.verifier.ToSynergyHostKeyVerifierAdapter) SshClient(com.sshtools.client.SshClient) SshException(com.jn.agileway.ssh.client.SshException)

Example 10 with SshException

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

the class SynergySessionedChannel method internalExec.

@Override
protected void internalExec(String command) throws SshException {
    try {
        RequestFuture future = channel.executeCommand(command);
        future.waitForever();
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
}
Also used : RequestFuture(com.sshtools.common.ssh.RequestFuture) 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