localPort = server.getPort(); log.log(Level.INFO, "CRaSSHD started on port " + localPort);
public int getPort() { return sshd.getPort(); }
public void putFile(String fileName, final String content) throws Exception { JSch jsch = new JSch(); Hashtable config = new Hashtable(); config.put("StrictHostKeyChecking", "no"); JSch.setConfig(config); Session session = jsch.getSession(user, "localhost", sshd.getPort()); session.setPassword(password); session.connect(); Channel channel = session.openChannel("sftp"); channel.connect(); ChannelSftp sftpChannel = (ChannelSftp) channel; sftpChannel.cd(baseDir); sftpChannel.put(new ByteArrayInputStream(content.getBytes()), fileName); if (sftpChannel.isConnected()) { sftpChannel.exit(); } if (session.isConnected()) { session.disconnect(); } filesToCleanup.add(FileSystems.getDefault().getPath(baseDir+FileSystems.getDefault().getSeparator()+fileName)); }
public InputStream getFile(String fileName) throws Exception { JSch jsch = new JSch(); Hashtable config = new Hashtable(); config.put("StrictHostKeyChecking", "no"); JSch.setConfig(config); Session session = jsch.getSession(user, "localhost", sshd.getPort()); session.setPassword(password); session.connect(); Channel channel = session.openChannel("sftp"); channel.connect(); ChannelSftp sftpChannel = (ChannelSftp) channel; sftpChannel.cd(baseDir); InputStream inputStream = sftpChannel.get(fileName); if (sftpChannel.isConnected()) { sftpChannel.exit(); } if (session.isConnected()) { session.disconnect(); } return inputStream; }
localPort = server.getPort(); log.log(Level.INFO, "CRaSSHD started on port " + localPort);
localPort = server.getPort(); log.log(Level.INFO, "CRaSSHD started on port " + localPort);
this.port = sshd.getPort(); return this.port;
this.port = sshd.getPort(); return this.port;
/** * creates a new Config with the ssh hostname and port set to connect to the provided server. * * @param sshd the server to configure for * @param sshKey the public key location to configure * @param existing the existing configuration * @return a new Config * @see Config#Config(IGerritHudsonTriggerConfig) */ public static Config getConfigFor(final SshServer sshd, KeyPairFiles sshKey, IGerritHudsonTriggerConfig existing) { Config c = new Config(existing); String host = sshd.getHost(); if (StringUtils.isBlank(host)) { c.setGerritHostName("localhost"); } else { c.setGerritHostName(host); } c.setGerritSshPort(sshd.getPort()); if (sshKey != null) { c.setGerritAuthKeyFile(sshKey.getPrivateKey()); } return c; }