return answers;
}
});
try {
ClientSession sshSession = client.connect(username, hostname, port).await().getSession();
Object oldIgnoreInterrupts = this.session.get(Session.IGNORE_INTERRUPTS);
try {
if (password != null) {
sshSession.addPasswordIdentity(password);
}
sshSession.auth().verify();
System.out.println("Connected");
this.session.put( Session.IGNORE_INTERRUPTS, Boolean.TRUE );
StringBuilder sb = new StringBuilder();
if (command != null) {
for (String cmd : command) {
if (sb.length() > 0) {
sb.append(' ');
}
sb.append(cmd);
}
}
ClientChannel channel;
if (sb.length() > 0) {
channel = sshSession.createChannel("exec", sb.append("\n").toString());
channel.setIn(new ByteArrayInputStream(new byte[0]));
} else {
channel = sshSession.createChannel("shell");
channel.setIn(new NoCloseInputStream(System.in));
((ChannelShell) channel).setPtyColumns(getTermWidth());
((ChannelShell) channel).setupSensibleDefaultPty();
((ChannelShell) channel).setAgentForwarding(true);
Object ctype = session.get("LC_CTYPE");
if (ctype != null) {
((ChannelShell) channel).setEnv("LC_CTYPE", ctype.toString());
}
}
channel.setOut(new NoCloseOutputStream(System.out));
channel.setErr(new NoCloseOutputStream(System.err));
channel.open().verify();
channel.waitFor(ClientChannel.CLOSED, 0);
} finally {
session.put( Session.IGNORE_INTERRUPTS, oldIgnoreInterrupts );
sshSession.close(false);
}
} finally {
client.stop();
}