@Override public void download(String remotePath, String localPath) throws IOException { download(remotePath, new FileSystemFile(localPath)); }
@Test public void shouldSCPDownloadFile() throws IOException { SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer(); assertFalse(targetFile.exists()); scpFileTransfer.download(sourceFile.getAbsolutePath(), targetDir.getAbsolutePath()); assertTrue(targetFile.exists()); }
@Test public void shouldSCPDownloadFileWithBandwidthLimit() throws IOException { // Limit download transfer at 128Ko/s SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer().bandwidthLimit(1024); assertFalse(targetFile.exists()); scpFileTransfer.download(sourceFile.getAbsolutePath(), targetDir.getAbsolutePath()); assertTrue(targetFile.exists()); }
@Test public void shouldSCPDownloadFileWithoutPathEscaping() throws IOException { SCPFileTransfer scpFileTransfer = sshClient.newSCPFileTransfer(); assertFalse(targetFile.exists()); File file = tempFolder.newFile("new file.txt"); FileUtil.writeToFile(file, "Some content"); scpFileTransfer.download(tempFolder.getRoot().getAbsolutePath() + "/new file.txt", targetFile.getAbsolutePath()); assertTrue(targetFile.exists()); assertThat(FileUtil.readFromFile(targetFile), CoreMatchers.containsString("Some content")); } }
@Override public void download(String remotePath, String localPath) throws IOException { download(remotePath, new FileSystemFile(localPath)); }
@Override public void download(String remotePath, String localPath) throws IOException { download(remotePath, new FileSystemFile(localPath)); }
public void transfertFile(String remoteFile, File localFile) throws IOException { ssh.newSCPFileTransfer().download(remoteFile, new FileSystemFile(localFile)); }
public Map<String, ?> processOutput(InvocationContext context) throws ProviderException { ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType(); try { // Get the Stdouts and StdErrs String timeStampedServiceName = GfacUtils.createUniqueNameForService(context.getServiceName()); File localStdOutFile = File.createTempFile(timeStampedServiceName, "stdout"); File localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr"); SCPFileTransfer fileTransfer = ssh.newSCPFileTransfer(); fileTransfer.download(app.getStandardOutput(), localStdOutFile.getAbsolutePath()); fileTransfer.download(app.getStandardError(), localStdErrFile.getAbsolutePath()); String stdOutStr = GfacUtils.readFileToString(localStdOutFile.getAbsolutePath()); String stdErrStr = GfacUtils.readFileToString(localStdErrFile.getAbsolutePath()); return OutputUtils.fillOutputFromStdout(context.<ActualParameter> getOutput(), stdOutStr); } catch (XmlException e) { throw new ProviderException("Cannot read output:" + e.getMessage(), e); } catch (ConnectionException e) { throw new ProviderException(e.getMessage(), e); } catch (TransportException e) { throw new ProviderException(e.getMessage(), e); } catch (IOException e) { throw new ProviderException(e.getMessage(), e); } }
public static void scpDownload(HostInfo hostInfo, FromTo fromTo) throws IOException { SSHClient ssh = getSshClient(hostInfo); try { Session session = ssh.startSession(); session.allocateDefaultPTY(); try { ssh.newSCPFileTransfer().download(fromTo.from, fromTo.to); } finally { session.close(); } } finally { ssh.disconnect(); ssh.close(); } }