if (config.getPassword() != null) {
session.addPasswordIdentity(config.getPassword());
}
session.auth().verify();
ClientChannel channel;
if (config.getCommand().length() > 0) {
channel = session.createChannel("exec", config.getCommand() + "\n");
channel.setIn(new ByteArrayInputStream(new byte[0]));
} else {
TerminalFactory.registerFlavor(TerminalFactory.Flavor.UNIX, NoInterruptUnixTerminal.class);
terminal = TerminalFactory.create();
channel = session.createChannel("shell");
ConsoleInputStream in = new ConsoleInputStream(terminal.wrapInIfNeeded(System.in));
new Thread(in).start();
channel.setIn(in);
((ChannelShell) channel).setPtyColumns(terminal != null ? terminal.getWidth() : 80);
((ChannelShell) channel).setupSensibleDefaultPty();
((ChannelShell) channel).setAgentForwarding(true);
String ctype = System.getenv("LC_CTYPE");
if (ctype == null) {
ctype = Locale.getDefault().toString() + "."
+ System.getProperty("input.encoding", Charset.defaultCharset().name());
}
((ChannelShell) channel).setEnv("LC_CTYPE", ctype);
}
channel.setOut(AnsiConsole.wrapOutputStream(System.out));
channel.setErr(AnsiConsole.wrapOutputStream(System.err));
channel.open();
channel.waitFor(ClientChannel.CLOSED, 0);
if (channel.getExitStatus() != null) {
exitStatus = channel.getExitStatus();
}
} catch (Throwable t) {
if (config.getLevel() > SimpleLogger.WARN) {
t.printStackTrace();
} else {