Пример #1
0
 /**
  * Get connection info for use in diagnostics messages
  *
  * @param session the session
  * @return a string to use in messages
  */
 public static String getSessionInfo(Session session) {
   if (session == null) {
     return "Not connected to any host";
   } else {
     return "SSH connection to " + session.getHost() + ":" + session.getPort();
   }
 }
Пример #2
0
 /**
  * Establish the connection to the server if not yet connected, and listen to ivy events for
  * closing connection when resolve is finished. Not meant to be used in multi threaded
  * environment.
  *
  * @return the ChannelSftp with which a connection is established
  * @throws IOException if any connection problem occurs
  */
 private ChannelSftp getSftpChannel(String pathOrUri) throws IOException {
   Session session = getSession(pathOrUri);
   String host = session.getHost();
   ChannelSftp channel = SshCache.getInstance().getChannelSftp(session);
   if (channel == null) {
     try {
       channel = (ChannelSftp) session.openChannel("sftp");
       channel.connect();
       Message.verbose(":: SFTP :: connected to " + host + "!");
       SshCache.getInstance().attachChannelSftp(session, channel);
     } catch (JSchException e) {
       IOException ex = new IOException(e.getMessage());
       ex.initCause(e);
       throw ex;
     }
   }
   return channel;
 }