public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, String localFile, String fileMode, int connectTimeoutInMs, 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)) { 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)) { 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 scpClient.put(localFile, remoteTargetDirectory); } finally { if (conn != null) conn.close(); } }
public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, byte[] data, String remoteFileName, String fileMode, int connectTimeoutInMs, 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)) { 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)) { 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); } finally { if (conn != null) conn.close(); } }
@Override public String uploadFile(String srcFile, String destDir) { String res = ""; File f = new File(srcFile); if (!f.exists()) { res = "Error in io:" + srcFile + " dose not exist!"; return res; } try { SCPClient client = connection.createSCPClient(); client.put(srcFile, destDir); } catch (IOException e) { res = "Error in io:" + e.getMessage(); } return res; }
SCPClient scp = conn.createSCPClient();
SCPClient scp = conn.createSCPClient();
scpClient = conn.createSCPClient();
scpClient = conn.createSCPClient(); if (fileMode != null) { scpClient.put(data, remoteFileName, remoteTargetDirectory, fileMode);
SCPClient scp = conn.createSCPClient();
SCPClient scp = conn.createSCPClient(); String initScript = computer.getNode().initScript; String tmpDir = (Util.fixEmptyAndTrim(computer.getNode().tmpDir) != null ? computer.getNode().tmpDir : "/tmp");
SCPClient scp = conn.createSCPClient(); String initScript = computer.getNode().initScript; String tmpDir = (Util.fixEmptyAndTrim(computer.getNode().tmpDir) != null ? computer.getNode().tmpDir