List of usage examples for org.apache.commons.net.ftp FTPFile isDirectory
public boolean isDirectory()
From source file:br.gov.frameworkdemoiselle.behave.regression.repository.FTPRepository.java
private List<FTPFile> getFolders() throws IOException { List<FTPFile> list = new ArrayList<FTPFile>(); for (FTPFile file : ftp.listFiles()) { if (file.isDirectory()) { list.add(file);//from w ww .ja v a2 s . c o m } } return list; }
From source file:ftp.search.Index.java
private void insertFiles(String ftp, String path, Statement stmt, FTPClient ftpClient) throws IOException, SQLException { FTPFile[] files = ftpClient.listFiles(path); for (FTPFile file : files) { String details = file.getName(); String details2 = details.replace("'", "''"); String path2 = ftp + path; String path3 = path2.replace("'", "''"); int isDir = 0; if (file.isDirectory()) { isDir = 1;//w w w . j ava 2 s . c o m } String query = "INSERT INTO fileindex (FileName,path,Folder) VALUES ('" + details2 + "' , '" + path3 + "' , " + isDir + ")"; System.out.println(query); stmt.executeUpdate(query); if (isDir == 1) { if (!path.contains("Games") && !(path.contains("College")) && !(path.contains("Cricket")) && !(path.contains("GeekHaven")) && !(path.contains("Windows")) && !(path.contains("Win")) && !(path.contains("Linux")) && !path.contains("INDEM") && !(path.contains("Telugu"))) { insertFiles(ftp, path + details + "/", stmt, ftpClient); } } } }
From source file:ilarkesto.integration.ftp.FtpClient.java
public boolean existsDir(String path) { FTPFile file = getFile(path); if (file == null) return false; return file.isDirectory(); }
From source file:de.thischwa.pmcms.tool.connection.ftp.FtpTransfer.java
/** * Changes to 'targetDir' and create the necessary subdirs. * /*from w w w . j ava 2 s. co m*/ * @param targetDirs If starts with '/' it will be interpreted as absolute to 'serverRootDir'! * @return True if was created/changed successful, otherwise false. * @throws ConnectionRunningException If any IOException was thrown by the FTPClient. */ private boolean chDirsConstruct(final String targetDirs) throws ConnectionException { try { boolean isAbsolute = false; // 1. check, if targetDir begins with '/' -> begin with server root dir if (targetDirs.startsWith("/")) isAbsolute = true; String tempDir; if (isAbsolute) tempDir = new PathConstructor().add(serverRootDir).add(targetDirs).setAbsolute().toString(); else tempDir = targetDirs; // 2. quick try, if requested dir exits, so we doesn't need the time expensive traversing if (ftpClient.changeWorkingDirectory(tempDir)) { logger.debug("[FTP] successfull chdir to:".concat(tempDir)); return true; } else { logger.debug("[FTP] couldn't change dir directly, have to traverse to: ".concat(tempDir)); } // 3. traverse and create if necessary String dirs[] = new PathConstructor().add(targetDirs).getDirs(); for (String dir : dirs) { if (StringUtils.isNotBlank(dir)) { FTPFile ftpFile = getByName(ftpClient.listFiles(), dir); if (ftpFile != null && ftpFile.isDirectory()) { // TODO Check if file exists with dir name! if (!ftpClient.changeWorkingDirectory(dir)) throw new ConnectionRunningException("Couldn't change to dir: " + dir); } else if (ftpFile == null) { if (!(ftpClient.makeDirectory(dir) && ftpClient.changeWorkingDirectory(dir))) throw new ConnectionRunningException("Couldn't create to dir: " + dir); } } } } catch (IOException e) { throw new ConnectionRunningException(e); } logger.debug("[FTP] Successfull change/create: ".concat(targetDirs)); return true; }
From source file:com.connection.factory.FtpConnectionApacheLib.java
@Override public List<RemoteFileObject> readAllFilesWalkinPath(String remotePath) { List<RemoteFileObject> willReturnObject = new ArrayList<>(); Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>(); RemoteFileObject object = null;//ww w. jav a 2 s .c om object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY); object.setDirectPath(remotePath); directorylist.add(object); try { while (!directorylist.isEmpty()) { object = directorylist.poll(); FTPFile[] fileListTemp = _ftpObj.listFiles(object.getPath()); for (FTPFile each : fileListTemp) { RemoteFileObject objectTemp = null; if (each.isDirectory()) { objectTemp = new FtpApacheFileObject(FileInfoEnum.DIRECTORY); objectTemp.setFileName(each.getName()); objectTemp.setAbsolutePath(object.getPath()); directorylist.add(objectTemp); } else if (each.isFile()) { objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE); objectTemp.setFileName(each.getName()); objectTemp.setAbsolutePath(object.getPath()); objectTemp.setFileSize(each.getSize()); objectTemp.setFileType(); objectTemp.setDate(each.getTimestamp().getTime()); willReturnObject.add(objectTemp); } } object = null; fileListTemp = null; } } catch (IOException ex) { return null; } catch (ConnectionException ex) { } return willReturnObject; }
From source file:com.connection.factory.FtpConnectionApacheLib.java
@Override public void readAllFilesWalkingPathWithListener(FileListener listener, String remotePath) { // List<RemoteFileObject> willReturnObject = new ArrayList<>(); Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>(); RemoteFileObject object = null;//from ww w . java 2 s. c om object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY); object.setDirectPath(remotePath); directorylist.add(object); try { while (!directorylist.isEmpty()) { object = directorylist.poll(); FTPFile[] fileListTemp = _ftpObj.listFiles(object.getPath()); for (FTPFile each : fileListTemp) { RemoteFileObject objectTemp = null; if (each.isDirectory()) { objectTemp = new FtpApacheFileObject(FileInfoEnum.DIRECTORY); objectTemp.setFileName(each.getName()); objectTemp.setAbsolutePath(object.getPath()); directorylist.add(objectTemp); } else if (each.isFile()) { objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE); objectTemp.setFileName(each.getName()); objectTemp.setAbsolutePath(object.getPath()); objectTemp.setFileSize(each.getSize()); objectTemp.setFileType(); objectTemp.setDate(each.getTimestamp().getTime()); listener.handleRemoteFile(object); } } object = null; fileListTemp = null; } } catch (IOException | ConnectionException ex) { // return null; } // return willReturnObject; // return willReturnObject; }
From source file:de.thischwa.pmcms.tool.connection.ftp.FtpTransfer.java
@Override public boolean download(final String sourcePath, OutputStream out) throws ConnectionRunningException { super.check(); boolean ok = false; PathAnalyzer pathAnalyzer = new PathAnalyzer(sourcePath); if (chDirAbsolute(pathAnalyzer.getDir())) { InputStream serverIn = null; try {/* w w w. j a va 2 s . c om*/ // 1. check, if Target exits on the server FTPFile serverFile = getByName(ftpClient.listFiles(), pathAnalyzer.getName()); if (serverFile == null || serverFile.isDirectory()) { logger.debug("[FTP] '" + sourcePath + "' doesn't exists or is a directory, - can't get it!"); return false; } // 2. retrieve the file if (!ftpClient.retrieveFile(sourcePath, out)) throw new ConnectionRunningException("Error while download [" + sourcePath + "]!"); ok = true; out.flush(); } catch (Exception e) { logger.error("[FTP] While getting/copying streams: " + e.getMessage(), e); throw new ConnectionRunningException("[FTP] While getting/copying streams: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(serverIn); IOUtils.closeQuietly(out); } } else throw new ConnectionRunningException("Couldn't change to target dir: " + pathAnalyzer.getDir()); if (ok) logger.debug("[FTP] successfull downloaded: " + sourcePath); else logger.debug("[FTP] download failed!"); return ok; }
From source file:it.greenvulcano.util.file.RegExFileFilter.java
public boolean accept(FTPFile file) { boolean fileTypeMatches = false; boolean nameMatches = false; boolean isModified = false; boolean isFile = !file.isDirectory(); fileTypeMatches = ((fileType == ALL) || ((fileType == FILES_ONLY) && isFile) || ((fileType == DIRECTORIES_ONLY) && !isFile)); if (fileTypeMatches) { if (pattern != null) { Matcher m = pattern.matcher(file.getName()); nameMatches = m.matches();/*from w w w . j a va 2 s.c om*/ } else { nameMatches = true; } if (nameMatches) { if (checkLastModified) { isModified = selectModifiedSince ? (file.getTimestamp().getTimeInMillis() > lastTimestamp) : (file.getTimestamp().getTimeInMillis() <= lastTimestamp); } else { isModified = true; } } } return fileTypeMatches && nameMatches && isModified; }
From source file:com.stacksync.desktop.connection.plugins.ftp.FtpTransferManager.java
public Map<String, RemoteFile> getDirectoryList(String folderPath) throws StorageException { try {/*w w w . j av a 2 s. c o m*/ Map<String, RemoteFile> files = new HashMap<String, RemoteFile>(); FTPFile[] ftpFiles = ftp.listFiles(getConnection().getPath() + "/" + folderPath); for (FTPFile f : ftpFiles) { files.put(folderPath + "/" + f.getName(), new RemoteFile(folderPath + "/" + f.getName(), f.getSize(), f)); if (f.isDirectory()) { files.putAll(getDirectoryList(folderPath + "/" + f.getName())); } } return files; } catch (IOException ex) { logger.error("Unable to list FTP directory.", ex); throw new StorageException(ex); } }
From source file:jenkins.plugins.publish_over_ftp.BapFtpClient.java
private void delete(final FTPFile ftpFile) throws IOException { if (ftpFile == null) throw new BapPublisherException(Messages.exception_client_fileIsNull()); final String entryName = ftpFile.getName(); if (".".equals(entryName) || "..".equals(entryName)) return;/*w w w . j av a 2 s . com*/ if (ftpFile.isDirectory()) { if (!changeDirectory(entryName)) throw new BapPublisherException(Messages.exception_cwdException(entryName)); delete(); if (!ftpClient.changeToParentDirectory()) throw new BapPublisherException(Messages.exception_client_cdup()); if (!ftpClient.removeDirectory(entryName)) throw new BapPublisherException(Messages.exception_client_rmdir(entryName)); } else { if (!ftpClient.deleteFile(entryName)) throw new BapPublisherException(Messages.exception_client_dele(entryName)); } }