List of usage examples for org.apache.commons.net.ftp FTPFile getName
public String getName()
From source file:no.imr.sea2data.stox.InstallerUtil.java
public static Boolean retrieveReadMeFromFTP(String ftpPath, String outFile) { return retrieveFromFTP(ftpPath, outFile, (FTPFile ftpFile) -> ftpFile.isFile() && ftpFile.getName().startsWith(README)); }
From source file:nz.govt.natlib.ndha.common.FileUtils.java
public static void removeFTPDirectory(FTPClient ftpClient, String directoryName) { try {/*w w w . jav a 2 s . c o m*/ ftpClient.changeWorkingDirectory(directoryName); for (FTPFile file : ftpClient.listFiles()) { if (file.isDirectory()) { FileUtils.removeFTPDirectory(ftpClient, file.getName()); } else { log.debug("Deleting " + file.getName()); ftpClient.deleteFile(file.getName()); } } ftpClient.changeWorkingDirectory(directoryName); ftpClient.changeToParentDirectory(); log.debug("Deleting " + directoryName); ftpClient.removeDirectory(directoryName); } catch (Exception ex) { } }
From source file:onl.area51.filesystem.ftp.client.FTPClient.java
default boolean appendFile(FTPFile remote, InputStream local) throws IOException { return appendFile(remote.getName(), local); }
From source file:onl.area51.filesystem.ftp.client.FTPClient.java
default boolean retrieveFile(FTPFile remote, OutputStream local) throws IOException { return retrieveFile(remote.getName(), local); }
From source file:onl.area51.filesystem.ftp.client.FTPClient.java
/** * Retrieve a file/*from w ww . ja va2s .c o m*/ * <p> * @param f FTPFile to retrieve * @param target Target directory, the file's name will be used * @param options CopyOption's * <p> * @return Path of file retrieved * <p> * @throws IOException */ default Path retrieve(FTPFile f, Path target, CopyOption... options) throws IOException { Path path = target.resolve(f.getName()); retrieve(f.getName(), path, options); return path; }
From source file:onl.area51.filesystem.ftp.client.FTPClient.java
default InputStream retrieveFileStream(FTPFile remote) throws IOException { return retrieveFileStream(remote.getName()); }
From source file:onl.area51.filesystem.ftp.client.FTPClient.java
default Reader retrieveReader(FTPFile remote) throws IOException { return retrieveReader(remote.getName()); }
From source file:onl.area51.gfs.grib2.job.GribRetriever.java
/** * Select the specified run.//from w w w .j a va 2 s . co m * <p> * @param date The date and hour of the required run * <p> * @throws java.io.IOException */ public void selectRun(LocalDateTime date) throws IOException { LOG.log(Level.INFO, "Retrieving directory listing"); client.changeWorkingDirectory(DIR); Stream<FTPFile> dirs = client.directories().filter(f -> f.getName().startsWith("gfs.")); if (date == null) { // Look for the most recent date dirs = dirs.sorted((a, b) -> b.getName().compareToIgnoreCase(a.getName())); } else { // Look for a specific date String filter = "gfs." + toGFSRunTime(date).format(DateTimeFormatter.BASIC_ISO_DATE); dirs = dirs.filter(f -> filter.equals(f.getName())); } @SuppressWarnings("ThrowableInstanceNotThrown") FTPFile dir = dirs.findFirst() .orElseThrow(() -> new FileNotFoundException("Failed to find remote gfs directory ")); client.changeWorkingDirectory(dir.getName()); String pwd = client.printWorkingDirectory(); LOG.log(Level.INFO, () -> "Now in directory " + pwd); }
From source file:onl.area51.gfs.grib2.job.GribRetriever.java
public Path retrieveOffset(Path dir, int offset, boolean forceRetrive) throws IOException { LOG.log(Level.INFO, () -> "Looking for GFS file for offset " + offset); String ending = String.format("z.pgrb2.0p25.f%03d", offset); @SuppressWarnings("ThrowableInstanceNotThrown") FTPFile remote = client.files().filter(f -> f.getName().startsWith("gfs.t")) .filter(f -> f.getName().endsWith(ending)).peek(f -> LOG.warning(f.getName())).findAny() .orElseThrow(() -> new FileNotFoundException("Unable to find GFS file for " + offset)); Path file = dir.resolve(remote.getName()); if (forceRetrive || client.isPathRetrievable(file, remote)) { LOG.log(Level.INFO, () -> "Retrieving " + remote.getSize() + " bytes to " + file); try (InputStream is = client.retrieveFileStream(remote)) { Files.copy(is, file, StandardCopyOption.REPLACE_EXISTING); }/*from w w w .jav a2 s.c o m*/ LOG.log(Level.INFO, () -> "Retrieved " + remote.getSize() + " bytes"); } else { LOG.log(Level.INFO, () -> "Skipping retrieval as local file is newer"); } return file; }
From source file:onl.area51.gfs.mapviewer.action.ImportGribAction.java
/** * View the GFS run files//from w w w . j a v a2s .c o m * <p> * @param client * @param dir * <p> * @throws Exception */ private void viewDirectory(FTPClient client, FTPFile dir) throws Exception { Main.setStatus("Retrieving %s directory listing...", dir.getName()); client.changeWorkingDirectory(DIR + "/" + dir.getName()); SelectFTPFile.select(client, this::selectDestName, "Select GFS Grib File", client.listFiles(), f -> f.isFile() && f.getName().matches("^gfs\\.t[0-9]{2}z\\.pgrb2\\.[0-2]p[0-9]{2}\\.f[0-9]{3}$")); }