List of usage examples for org.apache.commons.net.ftp FTPFile isDirectory
public boolean isDirectory()
From source file:de.aw.awlib.fragments.AWRemoteFileChooser.java
@Override public void onBindViewHolder(AWLibViewHolder holder, FTPFile file, int position) { TextView tv;//from w w w.j a v a2s . co m switch (holder.getItemViewType()) { case BACKTOPARENT: for (int resID : viewResIDs) { View view = holder.itemView.findViewById(resID); if (resID == R.id.folderImage) { ImageView img = (ImageView) view; img.setImageResource(R.drawable.ic_open_folder); } else if (resID == R.id.awlib_fileName) { tv = (TextView) view; if (mDirectoyList.size() == 0) { tv.setText("."); } else { tv.setText(file.getName()); } } else if (resID == R.id.awlib_fileData) { view.setVisibility(View.GONE); } } break; default: for (int resID : viewResIDs) { View view = holder.itemView.findViewById(resID); if (resID == R.id.folderImage) { ImageView img = (ImageView) view; if (file.isDirectory()) { img.setImageResource(R.drawable.ic_closed_folder); } else { img.setImageResource(R.drawable.ic_file_generic); } } else if (resID == R.id.awlib_fileName) { tv = (TextView) view; tv.setText(file.getName()); } else if (resID == R.id.awlib_fileData) { view.setVisibility(View.VISIBLE); tv = (TextView) view; tv.setText(Formatter.formatFileSize(getContext(), file.getSize())); } } } }
From source file:it.greenvulcano.util.remotefs.ftp.FTPManager.java
/** * @see it.greenvulcano.util.remotefs.RemoteManager#ls(String, String, date, * int, java.util.Map)// w w w . j a v a2 s .c om */ @Override public Set<FileProperties> ls(String remoteDirectory, String filenamePattern, Date modifiedSince, int fileTypeFilter, Map<String, String> optProperties) throws RemoteManagerException { checkConnected(); Set<FileProperties> resultsSet = new HashSet<FileProperties>(); try { changeWorkingDirectory(remoteDirectory); FTPFile[] results = ftpClient.listFiles(); int detectedFiles = (results != null ? results.length : 0); logger.debug(detectedFiles + " file entries DETECTED into current remote working directory"); if (results != null) { RegExFileFilter fileFilter = new RegExFileFilter(filenamePattern, fileTypeFilter, (modifiedSince != null) ? modifiedSince.getTime() : -1); for (FTPFile currFTPFile : results) { if (currFTPFile != null) { if (fileFilter.accept(currFTPFile)) { FileProperties currFile = new FileProperties(currFTPFile.getName(), currFTPFile.getTimestamp().getTimeInMillis(), currFTPFile.getSize(), currFTPFile.isDirectory(), currFTPFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION), currFTPFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION), currFTPFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)); resultsSet.add(currFile); } } else { logger.debug("Remote file entry NULL"); } } } return resultsSet; } catch (Exception exc) { throw new RemoteManagerException("FTP directory scan error", exc); } finally { if (isAutoconnect()) { disconnect(); } } }
From source file:adams.flow.source.FTPLister.java
/** * Executes the flow item./*from w ww . ja va2s . c o m*/ * * @return null if everything is fine, otherwise error message */ @Override protected String doExecute() { String result; FTPClient client; FTPFile[] files; result = null; m_Queue.clear(); client = m_Connection.getFTPClient(); if (m_ListDirs) { try { if (m_RemoteDir.length() > 0) client.changeWorkingDirectory(m_RemoteDir); files = client.listDirectories(); for (FTPFile file : files) { if (isStopped()) break; if (file == null) continue; if (m_RegExp.isEmpty() || m_RegExp.isMatchAll() || m_RegExp.isMatch(file.getName())) m_Queue.add(file.getName()); } } catch (Exception e) { result = handleException("Failed to list directories in '" + m_RemoteDir + "': ", e); } } if (result == null) { if (m_ListFiles) { try { if (m_RemoteDir.length() > 0) client.changeWorkingDirectory(m_RemoteDir); files = client.listFiles(); for (FTPFile file : files) { if (isStopped()) break; if (file == null) continue; if (file.isDirectory()) continue; if (m_RegExp.isEmpty() || m_RegExp.isMatchAll() || m_RegExp.isMatch(file.getName())) m_Queue.add(file.getName()); } } catch (Exception e) { result = handleException("Failed to list files in '" + m_RemoteDir + "': ", e); } } } if (isStopped()) m_Queue.clear(); return result; }
From source file:com.sos.VirtualFileSystem.FTP.SOSVfsFtp.java
/** * return a listing of the contents of a directory in short format on * the remote machine (without subdirectory) * * @param pathname on remote machine/* ww w.j a v a 2 s . c om*/ * @return a listing of the contents of a directory on the remote machine * @throws IOException * * @exception Exception * @see #dir() */ private Vector<String> getFilenames(final String pstrPathName, final boolean flgRecurseSubFolders) { String conMethodName = "getFilenames"; String strCurrentDirectory = null; // TODO vecDirectoryListing = null; prfen, ob notwendig Vector<String> vecDirectoryListing = null; if (vecDirectoryListing == null) { vecDirectoryListing = new Vector<String>(); String[] fileList = null; strCurrentDirectory = DoPWD(); String lstrPathName = pstrPathName.trim(); if (lstrPathName.length() <= 0) { lstrPathName = "."; } if (lstrPathName.equals(".")) { lstrPathName = strCurrentDirectory; } // if (1 == 1) { // try { // fileList = listNames(lstrPathName); // } // catch (IOException e) { // e.printStackTrace(System.err); // } // } try { listFiles = Client().listFiles(lstrPathName); } catch (IOException e) { RaiseException(e, HostID(SOSVfs_E_0105.params(conMethodName))); } if (listFiles == null || listFiles.length <= 0) { return vecDirectoryListing; } for (FTPFile listFile : listFiles) { String strCurrentFile = listFile.getName(); if (isNotHiddenFile(strCurrentFile) && strCurrentFile.trim().length() > 0) { // DoCD(strCurrentFile); // is this file-entry a subfolder? // boolean flgIsDirectory = isNegativeCommandCompletion() == false; boolean flgIsDirectory = listFile.isDirectory(); if (flgIsDirectory == false) { if (lstrPathName.startsWith("/") == false) { // JIRA SOSFTP-124 if (strCurrentFile.startsWith(strCurrentDirectory) == false) { strCurrentFile = addFileSeparator(strCurrentDirectory) + strCurrentFile; } } vecDirectoryListing.add(strCurrentFile); } else { if (flgIsDirectory && flgRecurseSubFolders == true) { DoCD(strCurrentDirectory); if (flgRecurseSubFolders) { logger.debug(String.format("")); Vector<String> vecNames = getFilenames(strCurrentFile, flgRecurseSubFolders); if (vecNames != null) { vecDirectoryListing.addAll(vecNames); } } } } } } } logger.debug("strCurrentDirectory = " + strCurrentDirectory); if (strCurrentDirectory != null) { DoCD(strCurrentDirectory); DoPWD(); } return vecDirectoryListing; }
From source file:net.sf.jfilesync.plugins.net.items.TCommonsFTP_plugin.java
protected TFileProperties extractFileProperties(FTPFile file, FTPFile[] filesInDir) throws IOException { TFileProperties prop = new TFileProperties(); prop.setFileName(file.getName());/*from w ww . ja v a 2s . c o m*/ final String cwd = ftpClient.printWorkingDirectory(); String fname = null; if (cwd.endsWith("/")) { fname = cwd + file.getName(); } else { fname = cwd + "/" + file.getName(); } prop.setAbsoluteFileName(fname); if (file.getName().startsWith(".")) { prop.setHiddenFlag(true); } // There is a little problem with ftp.getSize(), because it's sometimes // 0 prop.setFileSize(new BigInteger(Long.toString(file.getSize()))); // System.out.println(file.getName() + " , " + file.getTimestamp()); prop.setFileModTime(file.getTimestamp().getTimeInMillis()); // System.out.println("file: " + fname); // System.out.println("isDirectory: " + file.isDirectory()); prop.setDirectoryFlag(file.isDirectory()); prop.setLinkFlag(file.isSymbolicLink()); int permissions = 0; permissions |= file.isDirectory() ? FilePermissions.S_IFDIR : 0; permissions |= file.isSymbolicLink() ? FilePermissions.S_IFLNK : 0; permissions |= file.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION) ? FilePermissions.S_IRUSR : 0; permissions |= file.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION) ? FilePermissions.S_IWUSR : 0; permissions |= file.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION) ? FilePermissions.S_IXUSR : 0; permissions |= file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION) ? FilePermissions.S_IRGRP : 0; permissions |= file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION) ? FilePermissions.S_IWGRP : 0; permissions |= file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION) ? FilePermissions.S_IXGRP : 0; permissions |= file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION) ? FilePermissions.S_IROTH : 0; permissions |= file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION) ? FilePermissions.S_IWOTH : 0; permissions |= file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION) ? FilePermissions.S_IXOTH : 0; final TFileAttributes attr = new TFileAttributes(); attr.setPermissions(permissions); prop.setAttributes(attr); /* * what needs to be done is implement caching of directories which have * to be listed for link detection implement recursive link detection * for links to links SaHu July 2006 */ /* * if( file.isSymbolicLink() ) { System.out.println("link target : " + * file.getLink()); } */ // if( file.isSymbolicLink() ) { // // check if link points to dir // final String linkTarget = file.getLink(); // final String linkTargetBaseName = // getPathControl().basename(linkTarget); // //System.out.println("link target basename: " + linkTargetBaseName); // if( linkTarget != null ) { // String linkContaingPath = // getPathControl().getPathLevelUp(linkTarget); // FTPFile[] targetFiles = null; // if( linkContaingPath.equals("") || linkContaingPath.equals(cwd) ) { // targetFiles = filesInDir; // } else { // //System.out.println("check dir : " + linkContaingPath); // targetFiles = ftpClient.listFiles(linkContaingPath); // } // // // if( targetFiles != null ) { // for(int i=0; i<targetFiles.length; i++) { // //System.out.println("> " + targetFiles[i].getName()); // if( targetFiles[i].getName().equals(linkTargetBaseName) ) { // if( targetFiles[i].isDirectory() ) { // prop.setDirectoryFlag(true); // } // break; // } // } // } // } // } if (file.isSymbolicLink()) { final String linkTarget = file.getLink(); boolean result = ftpClient.changeWorkingDirectory(linkTarget); if (result) { prop.setDirectoryFlag(true); } ftpClient.changeWorkingDirectory(cwd); } return prop; }
From source file:com.sos.VirtualFileSystem.FTP.SOSVfsFtpBaseClass.java
/** * return a listing of a directory in long format on * the remote machine/*from w ww .jav a2s . co m*/ * * @param pathname on remote machine * @return a listing of the contents of a directory on the remote machine * @exception Exception * @see #nList() * @see #nList( String ) * @see #dir() */ @Override public SOSFileList dir(final String pathname, final int flag) { SOSFileList fileList = new SOSFileList(); FTPFile[] listFiles; try { listFiles = Client().listFiles(pathname); } catch (IOException e) { throw new RuntimeException(SOSVfs_E_128.params("listfiles", "dir"), e); } for (FTPFile listFile : listFiles) { if (flag > 0 && listFile.isDirectory()) { fileList.addAll(this.dir(pathname + "/" + listFile.toString(), flag >= 1024 ? flag : flag + 1024)); } else { if (flag >= 1024) { fileList.add(pathname + "/" + listFile.toString()); } else { fileList.add(listFile.toString()); } } } return fileList; }
From source file:com.clickha.nifi.processors.util.FTPTransferV2.java
private FileInfo newFileInfo(final FTPFile file, String path) { if (file == null) { return null; }//from w w w . j ava 2 s .co m final File newFullPath = new File(path, file.getName()); final String newFullForwardPath = newFullPath.getPath().replace("\\", "/"); StringBuilder perms = new StringBuilder(); perms.append(file.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION) ? "r" : "-"); perms.append(file.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION) ? "w" : "-"); perms.append(file.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION) ? "x" : "-"); perms.append(file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION) ? "r" : "-"); perms.append(file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION) ? "w" : "-"); perms.append(file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION) ? "x" : "-"); perms.append(file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION) ? "r" : "-"); perms.append(file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION) ? "w" : "-"); perms.append(file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION) ? "x" : "-"); FileInfo.Builder builder = new FileInfo.Builder().filename(file.getName()) .fullPathFileName(newFullForwardPath).directory(file.isDirectory()).size(file.getSize()) .lastModifiedTime(file.getTimestamp().getTimeInMillis()).permissions(perms.toString()) .owner(file.getUser()).group(file.getGroup()); return builder.build(); }
From source file:com.github.carlosrubio.org.apache.tools.ant.taskdefs.optional.net.FTP.java
/** * check FTPFiles to check whether they function as directories too * the FTPFile API seem to make directory and symbolic links incompatible * we want to find out if we can cd to a symbolic link * @param dir the parent directory of the file to test * @param file the file to test//from w ww . j ava2s. c o m * @return true if it is possible to cd to this directory * @since ant 1.6 */ private boolean isFunctioningAsFile(FTPClient ftp, String dir, FTPFile file) { if (file.isDirectory()) { return false; } else if (file.isFile()) { return true; } return !isFunctioningAsDirectory(ftp, dir, file); }
From source file:com.github.carlosrubio.org.apache.tools.ant.taskdefs.optional.net.FTP.java
/** * check FTPFiles to check whether they function as directories too * the FTPFile API seem to make directory and symbolic links incompatible * we want to find out if we can cd to a symbolic link * @param dir the parent directory of the file to test * @param file the file to test//from w w w . jav a 2 s . c o m * @return true if it is possible to cd to this directory * @since ant 1.6 */ private boolean isFunctioningAsDirectory(FTPClient ftp, String dir, FTPFile file) { boolean result = false; String currentWorkingDir = null; if (file.isDirectory()) { return true; } else if (file.isFile()) { return false; } try { currentWorkingDir = ftp.printWorkingDirectory(); } catch (IOException ioe) { getProject().log("could not find current working directory " + dir + " while checking a symlink", Project.MSG_DEBUG); } if (currentWorkingDir != null) { try { result = ftp.changeWorkingDirectory(file.getLink()); } catch (IOException ioe) { getProject().log("could not cd to " + file.getLink() + " while checking a symlink", Project.MSG_DEBUG); } if (result) { boolean comeback = false; try { comeback = ftp.changeWorkingDirectory(currentWorkingDir); } catch (IOException ioe) { getProject().log("could not cd back to " + dir + " while checking a symlink", Project.MSG_ERR); } finally { if (!comeback) { throw new BuildException("could not cd back to " + dir + " while checking a symlink"); } } } } return result; }
From source file:com.sos.VirtualFileSystem.FTP.SOSVfsFtpBaseClass.java
/** * return a listing of the contents of a directory in short format on * the remote machine (without subdirectory) * * @param pathname on remote machine//w w w.java 2 s.c o m * @return a listing of the contents of a directory on the remote machine * @throws IOException * * @exception Exception * @see #dir() */ private Vector<String> getFilenames(final String pstrPathName, final boolean flgRecurseSubFolders) { String strCurrentDirectory = null; // TODO vecDirectoryListing = null; prfen, ob notwendig vecDirectoryListing = null; if (vecDirectoryListing == null) { vecDirectoryListing = new Vector<String>(); String[] fileList = null; strCurrentDirectory = DoPWD(); String lstrPathName = pstrPathName.trim(); if (lstrPathName.length() <= 0) { lstrPathName = "."; } if (lstrPathName.equals(".")) { lstrPathName = strCurrentDirectory; } FTPFile[] objFTPFileList = null; try { objFTPFileList = Client().listFiles(lstrPathName); } catch (IOException e1) { e1.printStackTrace(); } // if (1 == 1) { // try { // fileList = listNames(lstrPathName); // // fileList = listNames(pstrPathName); // } // catch (IOException e) { // e.printStackTrace(System.err); // } // } // else { // FTPFile[] objFtpFiles = Client().listFiles(lstrPathName); // if (objFtpFiles != null) { // int i = 0; // for (FTPFile ftpFile : objFtpFiles) { // fileList[i++] = ftpFile.getName(); // } // } // } if (objFTPFileList == null) { return vecDirectoryListing; } for (FTPFile ftpFile : objFTPFileList) { String strCurrentFile = ftpFile.getName(); if (isNotHiddenFile(strCurrentFile)) { if (flgRecurseSubFolders == false && ftpFile.isFile()) { if (strCurrentFile.startsWith(strCurrentDirectory) == false) strCurrentFile = strCurrentDirectory + "/" + strCurrentFile; vecDirectoryListing.add(strCurrentFile); } else { // DoCD(strCurrentFile); // is this file-entry a subfolder? // if (isNegativeCommandCompletion()) { if (ftpFile.isFile()) { if (strCurrentFile.startsWith(strCurrentDirectory) == false) strCurrentFile = strCurrentDirectory + "/" + strCurrentFile; vecDirectoryListing.add(strCurrentFile); } else { // DoCD(strCurrentDirectory); if (ftpFile.isDirectory() && flgRecurseSubFolders) { Vector<String> vecNames = getFilenames(strCurrentFile); if (vecNames != null) { vecDirectoryListing.addAll(vecNames); } } } } } } } logger.debug(SOSVfs_I_126.params(strCurrentDirectory)); if (strCurrentDirectory != null) { DoCD(strCurrentDirectory); DoPWD(); } return vecDirectoryListing; }