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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations