List of usage examples for org.apache.commons.net.ftp FTPFile isUnknown
public boolean isUnknown()
From source file:lucee.commons.io.res.type.ftp.FTPResource.java
@Override public boolean exists() { try {/*from w w w .j a va 2 s .c o m*/ provider.read(this); } catch (IOException e) { return true; } FTPResourceClient client = null; InputStream is = null; try { // getClient muss zuerst sein so wird verbindung geprueft client = provider.getClient(data); if (isRoot()) return true; FTPFile file = client.getFTPFile(this); if (file != null) { return !file.isUnknown(); } //String pathname = getInnerPath(); String p = getInnerPath(); if (!StringUtil.endsWith(p, '/')) p += "/"; if (client.listNames(p) != null) return true; return false; } catch (IOException e) { return false; } finally { IOUtil.closeEL(is); provider.returnClient(client); } }
From source file:nl.esciencecenter.xenon.adaptors.filesystems.ftp.FtpFileSystem.java
private PathAttributes convertAttributes(Path path, FTPFile attributes) { PathAttributesImplementation result = new PathAttributesImplementation(); result.setPath(path);/*www . j a v a 2s .c o m*/ result.setDirectory(attributes.isDirectory()); result.setRegular(attributes.isFile()); result.setOther(attributes.isUnknown()); result.setSymbolicLink(attributes.isSymbolicLink()); result.setLastModifiedTime(attributes.getTimestamp().getTimeInMillis()); result.setCreationTime(attributes.getTimestamp().getTimeInMillis()); result.setLastAccessTime(attributes.getTimestamp().getTimeInMillis()); result.setSize(attributes.getSize()); Set<PosixFilePermission> permission = getPermissions(attributes); result.setExecutable(permission.contains(PosixFilePermission.OWNER_EXECUTE)); result.setReadable(permission.contains(PosixFilePermission.OWNER_READ)); result.setWritable(permission.contains(PosixFilePermission.OWNER_WRITE)); result.setPermissions(permission); result.setGroup(attributes.getGroup()); result.setOwner(attributes.getUser()); return result; }
From source file:org.apache.flume.source.FTPSource.java
@SuppressWarnings("UnnecessaryContinue") public void discoverElements(FTPClient ftpClient, String parentDir, String currentDir, int level) throws IOException { String dirToList = parentDir; if (!currentDir.equals("")) { dirToList += "/" + currentDir; }/*from w ww . j av a2 s . co m*/ FTPFile[] subFiles = ftpClient.listFiles(dirToList); if (subFiles != null && subFiles.length > 0) { for (FTPFile aFile : subFiles) { String currentFileName = aFile.getName(); if (currentFileName.equals(".") || currentFileName.equals("..")) { log.info("Skip parent directory and directory itself"); continue; } if (aFile.isDirectory()) { log.info("[" + aFile.getName() + "]"); ftpClient.changeWorkingDirectory(parentDir); discoverElements(ftpClient, dirToList, aFile.getName(), level + 1); continue; } else if (aFile.isFile()) { //aFile is a regular file ftpClient.changeWorkingDirectory(dirToList); existFileList.add(dirToList + "/" + aFile.getName()); //control of deleted files in server String fileName = aFile.getName(); if (!(sizeFileList.containsKey(dirToList + "/" + aFile.getName()))) { //new file ftpSourceCounter.incrementFilesCount(); InputStream inputStream = null; try { inputStream = ftpClient.retrieveFileStream(aFile.getName()); listener.fileStreamRetrieved(); readStream(inputStream, 0); boolean success = inputStream != null && ftpClient.completePendingCommand(); //mandatory if (success) { sizeFileList.put(dirToList + "/" + aFile.getName(), aFile.getSize()); saveMap(sizeFileList); ftpSourceCounter.incrementFilesProcCount(); log.info("discovered: " + fileName + " ," + sizeFileList.size()); } else { handleProcessError(fileName); } } catch (FTPConnectionClosedException e) { handleProcessError(fileName); log.error("Ftp server closed connection ", e); continue; } ftpClient.changeWorkingDirectory(dirToList); continue; } else { //known file long dif = aFile.getSize() - sizeFileList.get(dirToList + "/" + aFile.getName()); if (dif > 0) { //known and modified long prevSize = sizeFileList.get(dirToList + "/" + aFile.getName()); InputStream inputStream = null; try { inputStream = ftpClient.retrieveFileStream(aFile.getName()); listener.fileStreamRetrieved(); readStream(inputStream, prevSize); boolean success = inputStream != null && ftpClient.completePendingCommand(); //mandatory if (success) { sizeFileList.put(dirToList + "/" + aFile.getName(), aFile.getSize()); saveMap(sizeFileList); ftpSourceCounter.incrementCountModProc(); log.info("modified: " + fileName + " ," + sizeFileList.size()); } else { handleProcessError(fileName); } } catch (FTPConnectionClosedException e) { log.error("Ftp server closed connection ", e); handleProcessError(fileName); continue; } ftpClient.changeWorkingDirectory(dirToList); continue; } else if (dif < 0) { //known and full modified existFileList.remove(dirToList + "/" + aFile.getName()); //will be rediscovered as new file saveMap(sizeFileList); continue; } ftpClient.changeWorkingDirectory(parentDir); continue; } } else if (aFile.isSymbolicLink()) { log.info(aFile.getName() + " is a link of " + aFile.getLink() + " access denied"); ftpClient.changeWorkingDirectory(parentDir); continue; } else if (aFile.isUnknown()) { log.info(aFile.getName() + " unknown type of file"); ftpClient.changeWorkingDirectory(parentDir); continue; } else { ftpClient.changeWorkingDirectory(parentDir); continue; } } //fin de bucle } //el listado no es vaco }