if (ch != null && ch.isConnected()) ch.disconnect();
private boolean isRunning() { return channel.getExitStatus() < 0 && channel.isConnected(); }
@Override public void destroy() { if (channel.isConnected()) channel.disconnect(); closeOutputStream(); }
setupStreams(); channel.connect(timeout > 0 ? timeout * 1000 : 0); if (!channel.isConnected()) { closeOutputStream(); throw new TransportException(uri,
@Override public void destroy() { if (channel.isConnected()) channel.disconnect(); }
private boolean isRunning() { return channel.getExitStatus() < 0 && channel.isConnected(); }
private boolean isRunning() { return channel.getExitStatus() < 0 && channel.isConnected(); }
@Override public int exitValue() throws IllegalThreadStateException { int exitStatus = channelExec.getExitStatus(); if (exitStatus == -1) { if (!channelExec.isConnected()) { // exit status for SIGHUP return 129; } throw new IllegalThreadStateException("Process not terminated"); } return exitStatus; }
@Override public int exitValue() throws IllegalThreadStateException { int exitStatus = channelExec.getExitStatus(); if (exitStatus == -1) { if (!channelExec.isConnected()) { // exit status for SIGHUP return 129; } throw new IllegalThreadStateException("Process not terminated"); } return exitStatus; }
@Override public void destroy() { if (channel.isConnected()) channel.disconnect(); closeOutputStream(); }
public void copyFile(Session session, String sourceFile, String destinationFile) { ChannelExec channel = (ChannelExec) session.openChannel("exec"); channel.setCommand("cp " + sourceFile + " " + destinationFile); channel.connect(); while(channel.isConnected()) { Thread.sleep(20); } int status = channel.getExitStatus(); if(status != 0) throw new CopyException("copy failed, exit status is " + status); }
/** * Gets the value of the specified environment variable. * * @param ses SSH session. * @param cmd environment variable name. * @return environment variable value. * @throws JSchException In case of SSH error. * @throws IOException If failed. */ private String exec(Session ses, String cmd) throws JSchException, IOException { ChannelExec ch = null; try { ch = (ChannelExec)ses.openChannel("exec"); ch.setCommand(cmd); ch.connect(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(ch.getInputStream()))) { return reader.readLine(); } } finally { if (ch != null && ch.isConnected()) ch.disconnect(); } }
/** * Disconnect the SSH session connection */ public void disconnect() { if (stdoutThread != null && stdoutThread.isAlive()) { stdoutThread.interrupt(); } if (stderrThread != null && stderrThread.isAlive()) { stderrThread.interrupt(); } if (execChannel != null && execChannel.isConnected()) { execChannel.disconnect(); } if (session != null) { session.disconnect(); } }
throw e; } finally { if (channel != null && channel.isConnected()) { channel.disconnect();
if ( channel.isConnected() ) { channel.disconnect();
if ( channel.isConnected() ) { channel.disconnect();
@Test(timeout = 5000) public void testExec(TestContext context) throws Exception { startShell(); Session session = createSession("paulo", "secret", false); session.connect(); ChannelExec channel = (ChannelExec) session.openChannel("exec"); channel.setCommand("the-command arg1 arg2"); channel.connect(); InputStream in = channel.getInputStream(); StringBuilder input = new StringBuilder(); while (!input.toString().equals("the_output")) { int a = in.read(); if (a == -1) { break; } input.append((char)a); } OutputStream out = channel.getOutputStream(); out.write("the_input".getBytes()); out.flush(); while (channel.isConnected()) { Thread.sleep(1); } assertEquals(2, channel.getExitStatus()); session.disconnect(); } }
if (channel != null && channel.isConnected()) { channel.disconnect(); command, application.getName()); } catch (IOException e) { if (channel != null && channel.isConnected()) { channel.disconnect();
setupStreams(); channel.connect(timeout > 0 ? timeout * 1000 : 0); if (!channel.isConnected()) { closeOutputStream(); throw new TransportException(uri,
setupStreams(); channel.connect(timeout > 0 ? timeout * 1000 : 0); if (!channel.isConnected()) { closeOutputStream(); throw new TransportException(uri,