public SSHAgent addSSH(String id, String host, Integer port, String username, File f) { log.debug("Creating new SSH connection for ID:" + id); SSHAgent ssh = new SSHAgent(host, port, username, f); try { if (!ssh.connect()) ssh = null; connections.put(id, ssh); } catch (SSHException e) { log.error(e.getMessage()); ssh = null; } return ssh; }
/** * Fetch an SSHAgent associated with the given ID * * @param id Managed system ID to which the SSHAgent is connected * @return Null if the agent does not exist or the connection cannot be formed */ public SSHAgent getSSH(String id) { SSHAgent ssh = connections.get(id); if (ssh != null) { log.debug("Using previously-opened connection: " + id); if (!ssh.isAuthenticationComplete()) { try { if (!ssh.connect()) ssh = null; } catch (SSHException e) { log.error(e.getMessage()); } } } return ssh; }