ch = (ChannelShell)ses.openChannel("shell"); ch.connect(); try (PrintStream out = new PrintStream(ch.getOutputStream(), true)) { out.println(cmd); Pattern ptrn = Pattern.compile(regexp); try (BufferedReader reader = new BufferedReader(new InputStreamReader(ch.getInputStream()))) { String line; if (ch != null && ch.isConnected()) ch.disconnect();
channelShell.setPty(usePseudoTerminal); channelShell.setAgentForwarding(agentForwarding); final OutputStream shellIn = channelShell.getOutputStream(); final InputStream shellOut = channelShell.getInputStream(); channelShell.connect(connectTimeout);
channel.setPtyType("vt102"); channel.setEnv(env); Expect4j expect = new Expect4j(channel.getInputStream(), channel.getOutputStream()); channel.connect(5 * 1000);
shell.setOutputStream(stream); shell.connect(); } catch (final JSchException e) { throw new SshException("Failed to connect SSH shell.", e); final Expect4j expect = new Expect4j(shell.getInputStream(), shell.getOutputStream()); return new TerminalResponse(shell.getExitStatus(), buffer.toString()); } catch (final SshTimeoutException e) { throw e; return new TerminalResponse(0, "Error"); } finally { if (shell != null && shell.isConnected()) { shell.disconnect();
channel.setPtySize(1024, 20, 1024, 20); // commands should be < 1024 char channel.setOutputStream(consoleInput); channel.setInputStream(consoleOutput); consoleOutput = channel.getInputStream(); consoleInput = channel.getOutputStream(); channel.connect();
channel.connect(); try { channel.disconnect(); } catch (Exception ignore) {}
private void initShellConnection() throws JSchException, IOException { jsch = new JSch(); config = new Properties(); config.put("StrictHostKeyChecking", "no"); session = jsch.getSession("unknownid", "127.0.0.1", 22); session.setConfig(config); session.setPassword("unknownpw"); session.connect(CONNECTION_TIMEOUT); ChannelShell channel = (ChannelShell) session.openChannel("shell"); shellPrintStream = new PrintStream(channel.getOutputStream(), true); channel.setOutputStream(null); channel.setInputStream(null); channel.connect(CONNECTION_TIMEOUT); channel.setOutputStream(System.out); checkForRosCore(); }
@Test public void testResizeHandler(TestContext context) throws Exception { Async async = context.async(); termHandler = term -> { term.resizehandler(v -> { context.assertEquals(20, term.width()); context.assertEquals(10, term.height()); async.complete(); }); }; startShell(); Session session = createSession("paulo", "secret", false); session.connect(); ChannelShell channel = (ChannelShell) session.openChannel("shell"); channel.connect(); OutputStream out = channel.getOutputStream(); channel.setPtySize(20, 10, 20 * 8, 10 * 8); out.flush(); channel.disconnect(); session.disconnect(); }
inputStream = channel.getInputStream(); outputStream = channel.getOutputStream(); channel.connect(); } catch (JSchException e) { throw new IOException(e);
session = createSession(output); channel = (ChannelShell) session.openChannel("shell"); channel.setOutputStream(output, true); channel.setExtOutputStream(output, true); channel.setPty(Boolean.FALSE); in = IOUtils.getInputStreamFromString(wrapperShell); channel.setInputStream(in, true); channel.connect(); boolean exit = false; StringBuffer stringBuffer = new StringBuffer(); if (logger.isInfoEnabled()) { logger.info("[GSSH]-shell exit status is " + channel.getExitStatus());
ChannelShell shellChannel = (ChannelShell) session.openChannel("shell"); shellChannel.setOutputStream(outputStream, true); InputStream in = new PipedInputStream(); PipedOutputStream pin = new PipedOutputStream((PipedInputStream) in); shellChannel.setInputStream(in); shellChannel.connect(); pin.write("ls \r").getBytes());
ChannelShell channel = openShellChannel(); OutputStream outputStream = channel.getOutputStream(); PrintStream commander = new PrintStream(outputStream, true); // Print logs channel.setOutputStream(System.out, true); // exec the command commander.println(command);
public void disconnect() throws IOException { try { if (channel != null) channel.disconnect(); } catch (RuntimeException e) { e.printStackTrace();} try { if (session != null) session.disconnect(); } catch (RuntimeException e) { e.printStackTrace();} }
((ChannelShell) channel).setPty(usePseudoTerminal); ((ChannelShell) channel).setAgentForwarding(agentForwarding); InputStream in = new ByteArrayInputStream(command.getBytes(characterSet)); channel.setInputStream(in);
@Test public void testExitCode() throws Exception { server(conn -> { conn.setStdinHandler(bytes -> { conn.close(25); }); }); assertConnect(); assertWrite("whatever"); long timeout = System.currentTimeMillis() + 5000; while (!channel.isClosed()) { assertTrue(System.currentTimeMillis() < timeout); Thread.sleep(10); } assertEquals(25, channel.getExitStatus()); }
public void setPtySize(int width, int height) { ((ChannelShell)channel).setPtySize((int) Math.floor(width / 7.2981), (int) Math.floor(height / 17), width, height); } }
((ChannelShell) channel).setAgentForwarding(true); ((ChannelShell) channel).setPtyType("xterm");
public SshShell createShell(String termType, int colWidth, int rowHeight, int pixWidth, int pixHeight, byte[] terminalModes) throws SshException { try { ChannelShell channel = (ChannelShell) session.openChannel("shell"); if (termType != null) { channel.setTerminalMode(terminalModes == null || terminalModes.length == 0 ? new byte[0] : terminalModes); channel.setPtyType(termType, colWidth, rowHeight, pixWidth, pixHeight); } return new JschSshShell(getConfiguration(), channel) { protected void onChannelClose() throws SshException { channelCount--; } protected void onShellOpen() throws SshException { channelCount++; } }; } catch (JSchException e) { throw new SshException("Failed to create shell channel.", e); } }
if (newChannel instanceof ChannelShell) { ChannelShell channelShell = (ChannelShell) newChannel; channelShell.setPtyType("ANSI", TERMINAL_WIDTH, TERMINAL_HEIGHT, TERMINAL_WIDTH_IN_PIXELS, TERMINAL_HEIGHT_IN_PIXELS);