List of usage examples for org.apache.commons.net.ftp FTPFile isDirectory
public boolean isDirectory()
From source file:com.github.fge.ftpfs.io.commonsnetimpl.CommonsNetFtpAgent.java
private static void handleFailedDirectoryList(final String dir, final FTPFile file) throws FileSystemException { throw file.isDirectory() ? new AccessDeniedException(dir) : new NotDirectoryException(dir); }
From source file:com.microsoft.azuretools.utils.WebAppUtils.java
public static boolean doesRemoteFolderExist(FTPClient ftp, String path, String folderName) throws IOException { FTPFile[] files = ftp.listFiles(path); for (FTPFile file : files) { if (file.isDirectory() && file.getName().equalsIgnoreCase(folderName)) { return true; }//from www. j a va2 s . c o m } return false; }
From source file:com.seajas.search.contender.service.modifier.ArchiveModifierService.java
/** * Recursively retrieve a directory listing from the FTP server. * /*from w w w. jav a2 s . c om*/ * @param path * @param ftpClient * @param exclusionExpression * @return List<FTPFile> * @throws IOException */ private static List<ArchiveFile> retrieveFiles(final String path, final FTPClient ftpClient, final String exclusionExpression) throws IOException { List<FTPFile> files = Arrays.asList(ftpClient.listFiles(path)); List<ArchiveFile> result = new Vector<ArchiveFile>(); for (FTPFile file : files) if (!file.getName().equals(".") && !file.getName().equals("..")) { if (file.isDirectory()) { String folderPath = path + (path.endsWith("/") ? "" : "/") + file.getName(); if (!StringUtils.hasText(exclusionExpression) || !folderPath.matches(exclusionExpression)) result.addAll(retrieveFiles(folderPath, ftpClient, exclusionExpression)); } else if (file.isFile() && (!StringUtils.hasText(exclusionExpression) || !(path + "/" + file.getName()).matches(exclusionExpression))) result.add(new ArchiveFile(path, file)); } return result; }
From source file:com.zurich.lifeac.intra.control.FTPUtil.java
public static void downloadDirectory(FTPClient ftpClient, String parentDir, String currentDir, String saveDir) throws IOException {//parentDir=remote_edir ,saveDir=loc_dir String dirToList = parentDir; if (!currentDir.equals("")) { dirToList += "/" + currentDir; }/*from www. ja v a 2s. c om*/ System.out.println("downloadDirectory >dirToList:" + dirToList); FTPFile[] subFiles = ftpClient.listFiles(dirToList); if (subFiles != null && subFiles.length > 0) { for (FTPFile aFile : subFiles) { String currentFileName = aFile.getName(); if (currentFileName.equals(".") || currentFileName.equals("..")) { // skip parent directory and the directory itself continue; } String filePath = parentDir + "/" + currentDir + "/" + currentFileName; if (currentDir.equals("")) { filePath = parentDir + "/" + currentFileName; } //System.out.println(filePath); String newDirPath = saveDir + File.separator + currentDir + File.separator + currentFileName; if (currentDir.equals("")) { newDirPath = saveDir + File.separator + currentFileName; } if (aFile.isDirectory()) { // create the directory in saveDir // File newDir = new File(newDirPath); // boolean created = newDir.mkdirs(); // if (created) { // System.out.println("CREATED the directory: " + newDirPath); // } else { // System.out.println("COULD NOT create the directory: " + newDirPath); // } // // // download the sub directory // downloadDirectory(ftpClient, dirToList, currentFileName, // saveDir); } else { // download the file System.out.println("DOWNLOADED the file: " + filePath); boolean success = downloadSingleFile(ftpClient, filePath, newDirPath); if (success) { //if download success then delete the file. boolean deleted = ftpClient.deleteFile(filePath); if (deleted) { System.out.println("delete the file: " + filePath); } else { System.out.println("COULD NOT delete the file: " + filePath); } } } } } else { System.out.println("There are no .txt file"); } }
From source file:ftpclientgui.FTPListItemAdapter.java
@Override public FileListItem getFileListItem(FTPFile adaptee) { FileListItemTypes t = null;/*from w ww. ja v a 2s.co m*/ if (adaptee.isDirectory()) { t = FileListItemTypes.DIRECTORY; } else if (adaptee.isFile()) { t = FileListItemTypes.FILE; } return new FileListItem(adaptee.getName(), t); }
From source file:dhz.skz.citaci.weblogger.WlFileFilter.java
@Override public boolean accept(FTPFile file) { if (file.isDirectory()) return false; String strL = file.getName().toLowerCase(); String ptStr = "^(" + nazivPostaje + ")-(\\d{8})(.?)\\.csv"; Pattern pt = Pattern.compile(ptStr); Matcher m = pt.matcher(strL); if (m.matches()) { try {/* w w w .j av a2 s . com*/ Date sada = formatter.parse(m.group(2)); if (zadnji.getTime() - sada.getTime() < 24 * 3600 * 1000) { return true; } } catch (ParseException ex) { log.log(Level.SEVERE, null, ex); } } return false; }
From source file:dhz.skz.citaci.weblogger.zerospan.WlZeroSpanFileFilter.java
@Override public boolean accept(FTPFile file) { if (file.isDirectory()) return false; String strL = file.getName().toLowerCase(); String ptStr = "^(" + nazivPostaje + ")_c-(\\d{8})\\.csv"; Pattern pt = Pattern.compile(ptStr); Matcher m = pt.matcher(strL); if (m.matches()) { try {/*ww w . ja v a 2 s. c om*/ Date sada = formatter.parse(m.group(2)); if (zadnji.getTime() - sada.getTime() < 24 * 3600 * 1000) { return true; } } catch (ParseException ex) { log.log(Level.SEVERE, null, ex); } } return false; }
From source file:com.esri.gpt.control.webharvest.client.waf.FtpFileIterator.java
/** * Creates new resource.// w w w.j a va 2 s. com * @param file file * @return resource */ protected Resource newResource(FTPFile file) { if (file.isDirectory()) { return new FtpFolder(iterationContext, getFtpClient(), criteria, folder + "/" + file.getName()); } else if (file.isFile() && file.getName().toLowerCase().endsWith(".xml")) { if (criteria == null || criteria.getFromDate() == null || file.getTimestamp() == null || (criteria.getFromDate() != null && file.getTimestamp() != null && file.getTimestamp().after(criteria.getFromDate()))) { return new FtpFile(iterationContext, getFtpClient(), folder + "/" + file.getName()); } } return null; }
From source file:com.microsoft.azuretools.utils.WebAppUtils.java
public static void removeFtpDirectory(FTPClient ftpClient, String path, IProgressIndicator pi) throws IOException { String prefix = "Removing from FTP server: "; FTPFile[] subFiles = ftpClient.listFiles(path); if (subFiles.length > 0) { for (FTPFile ftpFile : subFiles) { if (pi != null && pi.isCanceled()) break; String currentFileName = ftpFile.getName(); if (currentFileName.equals(".") || currentFileName.equals("..")) { continue; // skip }/*from w w w . j ava2 s . c o m*/ String path1 = path + "/" + currentFileName; if (ftpFile.isDirectory()) { // remove the sub directory removeFtpDirectory(ftpClient, path1, pi); } else { // delete the file if (pi != null) pi.setText2(prefix + path1); ftpClient.deleteFile(path1); } } } if (pi != null) pi.setText2(prefix + path); ftpClient.removeDirectory(path); if (pi != null) pi.setText2(""); }
From source file:jcr.FTPParser.java
private void parse(String workingDirectory) throws RepositoryException, IOException, Exception { Node node = JcrUtils.getOrCreateByPath(jcrServerNodePath + workingDirectory, null, session); String encoded = new String(workingDirectory.getBytes("UTF-8"), "ISO-8859-1"); FTPFile[] files = client.listFiles(encoded); logger.log(Level.INFO, "Parse {0} item in directory: {1}", new Object[] { files.length, workingDirectory }); for (FTPFile file : files) { if (file.isDirectory()) { parse(workingDirectory + "/" + file.getName()); } else {//from w w w . j a v a 2s .c o m String remote = workingDirectory + "/" + file.getName(); if (remote.endsWith(".md5") || remote.endsWith(".md5sum")) { parseChecksumFile(remote); } else if (remote.endsWith(".tgz.desc") || remote.endsWith(".zip.desc")) { parseDescriptorFile(remote); } else { parseFile(remote, file.getSize()); } } } }