private static URIish createURI(Session session) { URIish uri = new URIish(); uri = uri.setScheme("ssh"); //$NON-NLS-1$ uri = uri.setUser(session.getUserName()); uri = uri.setHost(session.getHost()); uri = uri.setPort(session.getPort()); return uri; }
public int getPort() { return session.getPort(); }
if (port > 0 && port != session.getPort()) { session.setPort(port);
@Override public String getId() { return "//" + session.getUserName() + "@" + session.getHost() + ":" + session.getPort() + "/"; }
@Override public synchronized void close() { Session session = null; try { session = sshChannel.getSession(); } catch (JSchException e) { // Ignore as it only affects logging and normally shouldn't happen } int id = sshChannel.getId(); sshChannel.disconnect(); if (session != null) { LOG.trace("Disconnected port forwarding channel {} through host {}:{}", id, session.getHost(), session.getPort()); } else { LOG.trace("Disconnected port forwarding channel {}", id); } }
@Override public synchronized void close() { Session session = null; try { session = sshChannel.getSession(); } catch (JSchException e) { // Ignore as it only affects logging and normally shouldn't happen } int id = sshChannel.getId(); sshChannel.disconnect(); if (session != null) { LOG.trace("Disconnected port forwarding channel {} through host {}:{}", id, session.getHost(), session.getPort()); } else { LOG.trace("Disconnected port forwarding channel {}", id); } }
@Override public CliProcess execute(String command) { try { Session session = createSession(); LOGGER.info("Executing on {}@{}:{}: {}", session.getUserName(), session.getHost(), session.getPort(), command); ChannelExec channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(command); JSchCliProcess process = new JSchCliProcess(session, channel); process.connect(); return process; } catch (JSchException | IOException exception) { throw new RuntimeException(exception); } }
@Override public CliProcess execute(String command) { try { Session session = createSession(); LOGGER.info("Executing on {}@{}:{}: {}", session.getUserName(), session.getHost(), session.getPort(), command); ChannelExec channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(command); JSchCliProcess process = new JSchCliProcess(session, channel); process.connect(); return process; } catch (JSchException | IOException exception) { throw new RuntimeException(exception); } }
session.getPort(), executor.getExitStatus(), script, output.toString(), error.toString()));
@Override public void upload(Path file, String remotePath) { Session session = null; try { session = createSession(); LOGGER.info("Uploading {} onto {}@{}:{}:{}", file, session.getUserName(), session.getHost(), session.getPort(), remotePath); ChannelExec channel = (ChannelExec) session.openChannel("exec"); String command = "scp -t " + remotePath; channel.setCommand(command); OutputStream out = channel.getOutputStream(); InputStream in = channel.getInputStream(); sendSCPFile(file, channel, in, out); } catch (JSchException | IOException exception) { Throwables.propagate(exception); } finally { if (session != null) session.disconnect(); } }
@Override public void upload(Path file, String remotePath) { Session session = null; try { session = createSession(); LOGGER.info("Uploading {} onto {}@{}:{}:{}", file, session.getUserName(), session.getHost(), session.getPort(), remotePath); ChannelExec channel = (ChannelExec) session.openChannel("exec"); String command = "scp -t " + remotePath; channel.setCommand(command); OutputStream out = channel.getOutputStream(); InputStream in = channel.getInputStream(); sendSCPFile(file, channel, in, out); } catch (JSchException | IOException exception) { Throwables.propagate(exception); } finally { if (session != null) { session.disconnect(); } } }
/** * Creates a new instance of this class by connecting the direct TCPIP channel for port forwarding. * * @param sshChannel an unconnected {@link ChannelDirectTCPIP} created from a ssh session * @param dataConsumer the {@link DataConsumer} for receiving incoming data * @throws IOException if failed to connect to the channel */ DefaultPortForwarding(ChannelDirectTCPIP sshChannel, DataConsumer dataConsumer) throws IOException { sshChannel.setOutputStream(createIncomingOutputStream(dataConsumer)); this.outputStream = sshChannel.getOutputStream(); this.sshChannel = sshChannel; this.transferBuf = new byte[TRANSFER_SIZE]; try { sshChannel.connect(); Session session = sshChannel.getSession(); LOG.trace("Opened port forwarding channel {} through host {}:{}", sshChannel.getId(), session.getHost(), session.getPort()); } catch (JSchException e) { throw new IOException(e); } }
/** * Creates a new instance of this class by connecting the direct TCPIP channel for port forwarding. * * @param sshChannel an unconnected {@link ChannelDirectTCPIP} created from a ssh session * @param dataConsumer the {@link DataConsumer} for receiving incoming data * @throws IOException if failed to connect to the channel */ DefaultPortForwarding(ChannelDirectTCPIP sshChannel, DataConsumer dataConsumer) throws IOException { sshChannel.setOutputStream(createIncomingOutputStream(dataConsumer)); this.outputStream = sshChannel.getOutputStream(); this.sshChannel = sshChannel; this.transferBuf = new byte[TRANSFER_SIZE]; try { sshChannel.connect(); Session session = sshChannel.getSession(); LOG.trace("Opened port forwarding channel {} through host {}:{}", sshChannel.getId(), session.getHost(), session.getPort()); } catch (JSchException e) { throw new IOException(e); } }
private static URIish createURI(Session session) { URIish uri = new URIish(); uri = uri.setScheme("ssh"); //$NON-NLS-1$ uri = uri.setUser(session.getUserName()); uri = uri.setHost(session.getHost()); uri = uri.setPort(session.getPort()); return uri; }
private static URIish createURI(Session session) { URIish uri = new URIish(); uri = uri.setScheme("ssh"); //$NON-NLS-1$ uri = uri.setUser(session.getUserName()); uri = uri.setHost(session.getHost()); uri = uri.setPort(session.getPort()); return uri; }
" on server - " + session.getHost() + ":" + session.getPort() + " connecting user name - " + session.getUserName(), e);
" on server - " + session.getHost() + ":" + session.getPort() + " connecting user name - " + session.getUserName(), e);
if (port > 0 && port != session.getPort()) { session.setPort(port);