Java Code Examples for ch.ethz.ssh2.SCPClient#get()
The following examples show how to use
ch.ethz.ssh2.SCPClient#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScpService.java From wecube-platform with Apache License 2.0 | 7 votes |
public void getFile(String ip, Integer port, String user, String password, String privateKey, boolean usePassword, String remoteFile, String path) { Connection connection = new Connection(ip, port); try { connection.connect(); boolean isAuthed = isAuth(ip, port, user, password, privateKey, usePassword); if (isAuthed) { System.out.println("Authentication is successful!"); SCPClient scpClient = connection.createSCPClient(); scpClient.get(remoteFile, path); } else { System.out.println("Authentication failed!"); } } catch (IOException e) { e.printStackTrace(); } finally { connection.close(); } }
Example 2
Source File: ScpClientUtil.java From eladmin with Apache License 2.0 | 6 votes |
public void getFile(String remoteFile, String localTargetDirectory) { Connection conn = new Connection(ip, port); try { conn.connect(); boolean isAuthenticated = conn.authenticateWithPassword(username, password); if (!isAuthenticated) { System.err.println("authentication failed"); } SCPClient client = new SCPClient(conn); client.get(remoteFile, localTargetDirectory); } catch (IOException ex) { Logger.getLogger(SCPClient.class.getName()).log(Level.SEVERE, null, ex); }finally{ conn.close(); } }
Example 3
Source File: SSHExecutor.java From zkdoctor with Apache License 2.0 | 5 votes |
/** * 获取远程文件内容 * * @param remoteFile 远程文件名称,包含路径 * @return */ public Result getRemoteFile(String remoteFile) { try { SCPClient client = conn.createSCPClient(); OutputStream outputStream = new ByteArrayOutputStream(); client.get(remoteFile, outputStream); return new Result(true, outputStream.toString()); } catch (Exception e) { LOGGER.error("Get remoteFile {} error.", remoteFile, e); return new Result(e); } }
Example 4
Source File: SSHExecutor.java From PoseidonX with Apache License 2.0 | 5 votes |
/** * 获取远程文件内容 * * @param remoteFile 远程文件名称,包含路径 * @return */ public Result getRemoteFile(String remoteFile) { try { SCPClient client = conn.createSCPClient(); OutputStream outputStream = new ByteArrayOutputStream(); client.get(remoteFile, outputStream); return new Result(true, outputStream.toString()); } catch (Exception e) { LOGGER.error("Get remoteFile {} error.", remoteFile, e); return new Result(e); } }
Example 5
Source File: SSH2Util.java From util with Apache License 2.0 | 2 votes |
/** * 功能:使用ssh2 下载文件。 * @author 朱志杰 QQ:862990787 * Sep 2, 2013 10:03:40 AM * @param remoteFile 服务器上的文件路径。 * @param localTargetDirectory 下载到本地的文件夹路径。 * @throws IOException */ public void downloadFile(String remoteFile,String localTargetDirectory) throws IOException{ SCPClient scpClient = conn.createSCPClient(); scpClient.get(remoteFile,localTargetDirectory); //从远程获取文件 }