public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, String localFile, String fileMode) throws Exception { scpTo(host, port, user, pemKeyFile, password, remoteTargetDirectory, localFile, fileMode, DEFAULT_CONNECT_TIMEOUT, DEFAULT_KEX_TIMEOUT); }
public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, byte[] data, String remoteFileName, String fileMode) throws Exception { scpTo(host, port, user, pemKeyFile, password, remoteTargetDirectory, data, remoteFileName, fileMode, DEFAULT_CONNECT_TIMEOUT, DEFAULT_KEX_TIMEOUT); }
private static void uploadCert(final String nsIp, final String user, final String password, final String certFilename, final byte[] certData) throws ExecutionException { try { SshHelper.scpTo(nsIp, SSH_PORT, user, null, password, SSL_CERT_PATH, certData, certFilename, null); } catch (final Exception e) { throw new ExecutionException("Failed to copy private key to device " + e.getMessage()); } }
private static void uploadKey(final String nsIp, final String user, final String password, final String keyFilename, final byte[] keyData) throws ExecutionException { try { SshHelper.scpTo(nsIp, SSH_PORT, user, null, password, SSL_CERT_PATH, keyData, keyFilename, null); } catch (final Exception e) { throw new ExecutionException("Failed to copy private key to device " + e.getMessage()); } }
@Override public ExecutionResult createFileInVR(final String routerIp, final String path, final String filename, final String content) { final File permKey = new File("/root/.ssh/id_rsa.cloud"); boolean success = true; String details = "Creating file in VR, with ip: " + routerIp + ", file: " + filename; s_logger.debug(details); try { SshHelper.scpTo(routerIp, 3922, "root", permKey, null, path, content.getBytes(), filename, null); } catch (final Exception e) { s_logger.warn("Fail to create file " + path + filename + " in VR " + routerIp, e); details = e.getMessage(); success = false; } return new ExecutionResult(success, details); }
@Override public ExecutionResult createFileInVR(final String routerIp, final String filePath, final String fileName, final String content) { final File keyFile = getSystemVMKeyFile(); try { SshHelper.scpTo(routerIp, 3922, "root", keyFile, null, filePath, content.getBytes(Charset.forName("UTF-8")), fileName, null); } catch (final Exception e) { s_logger.warn("Fail to create file " + filePath + fileName + " in VR " + routerIp, e); return new ExecutionResult(false, e.getMessage()); } return new ExecutionResult(true, null); }
@Override public ExecutionResult createFileInVR(final String routerIp, final String path, final String filename, final String content) { final Connection conn = getConnection(); final String hostPath = "/tmp/"; s_logger.debug("Copying VR with ip " + routerIp + " config file into host " + _host.getIp()); try { SshHelper.scpTo(_host.getIp(), 22, _username, null, _password.peek(), hostPath, content.getBytes(Charset.defaultCharset()), filename, null); } catch (final Exception e) { s_logger.warn("scp VR config file into host " + _host.getIp() + " failed with exception " + e.getMessage().toString()); } final String rc = callHostPlugin(conn, "vmops", "createFileInDomr", "domrip", routerIp, "srcfilepath", hostPath + filename, "dstfilepath", path); s_logger.debug("VR Config file " + filename + " got created in VR, ip " + routerIp + " with content \n" + content); return new ExecutionResult(rc.startsWith("succ#"), rc.substring(5)); }
SshHelper.scpTo(controlIp, DEFAULT_DOMR_SSHPORT, "root", keyFile, null, "/tmp/", tmpCfgFileContents.toString().getBytes(Charset.forName("UTF-8")), routerIp.replace('.', '_') + ".cfg", null);
.scpTo(c.getIp(), 22, config .getAgentSshUserName(), null, config.getAgentSshPassword(),
public static void scpTo(final String host, final int port, final String user, final File pemKeyFile, final String password, final String remoteTargetDirectory, final String localFile, final String fileMode, final int connectTimeoutInMs, final int kexTimeoutInMs) throws Exception { com.trilead.ssh2.Connection conn = null; com.trilead.ssh2.SCPClient scpClient = null; try { conn = new com.trilead.ssh2.Connection(host, port); conn.connect(null, connectTimeoutInMs, kexTimeoutInMs); if (pemKeyFile == null) { if (!conn.authenticateWithPassword(user, password)) { final String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg); throw new Exception(msg); } } else { if (!conn.authenticateWithPublicKey(user, pemKeyFile, password)) { final String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg); throw new Exception(msg); } } scpClient = conn.createSCPClient(); if (fileMode != null) { scpClient.put(localFile, remoteTargetDirectory, fileMode); } else {
public static void scpTo(final String host, final int port, final String user, final File pemKeyFile, final String password, final String remoteTargetDirectory, final byte[] data, final String remoteFileName, final String fileMode, final int connectTimeoutInMs, final int kexTimeoutInMs) throws Exception { com.trilead.ssh2.Connection conn = null; com.trilead.ssh2.SCPClient scpClient = null; try { conn = new com.trilead.ssh2.Connection(host, port); conn.connect(null, connectTimeoutInMs, kexTimeoutInMs); if (pemKeyFile == null) { if (!conn.authenticateWithPassword(user, password)) { final String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg); throw new Exception(msg); } } else { if (!conn.authenticateWithPublicKey(user, pemKeyFile, password)) { final String msg = "Failed to authentication SSH user " + user + " on host " + host; s_logger.error(msg); throw new Exception(msg); } } scpClient = conn.createSCPClient(); if (fileMode != null) { scpClient.put(data, remoteFileName, remoteTargetDirectory, fileMode); } else { scpClient.put(data, remoteFileName, remoteTargetDirectory);