Example usage for org.apache.commons.net.ftp FTPFile isDirectory

List of usage examples for org.apache.commons.net.ftp FTPFile isDirectory

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp FTPFile isDirectory.

Prototype

public boolean isDirectory() 

Source Link

Document

Determine if the file is a directory.

Usage

From source file:gtu._work.ui.ObnfCheckPDFErrorUI.java

private void checkBtnActionPerformed() {
    try {/*from w w w. j av a 2  s  . co m*/
        for (FtpSite ftpSite : FtpSite.values()) {
            FtpUtil ftpUtil = new FtpUtil();
            ftpUtil.connect(ftpSite.ip, ftpSite.port, ftpSite.userId, ftpSite.password, false);
            FTPClient ftp = ftpUtil.getFtp();
            logArea.append("?" + ftpSite.label + "\n");
            ftp.enterLocalPassiveMode();
            FTPFile[] ftpFiles = ftp.listFiles(ftpSite.path1);
            logArea.append("-->" + ftpSite.path1 + "\n");
            for (int i = 0; i < ((ftpFiles == null) ? 0 : ftpFiles.length); i++) {
                FTPFile ftpFile = ftpFiles[i];
                if (ftpFile.isDirectory()) {
                    String p = ftpSite.path1 + "/" + ftpFile.getName() + "/" + ftpSite.path2 + "/";
                    logArea.append("-->" + p + "\n");
                    List<FtpFileInfo> fileList = new ArrayList<FtpFileInfo>();
                    ftpUtil.scanFindFile(p, ".*", fileList, ftp);
                    for (FtpFileInfo f : fileList) {
                        logArea.append("-->" + f.getAbsolutePath() + "--" + f.getSize() + "\n");
                        if (!f.isDirectory() && f.getSize() == 0) {
                            logArea.append("##" + ftpSite.label + "\t" + f.getAbsolutePath() + "\n");
                        }
                    }
                }
            }

            ftpUtil.disconnect();
            logArea.append("?:" + ftpSite.label);
        }

        JCommonUtil._jOptionPane_showMessageDialog_info("!");
    } catch (Exception ex) {
        JCommonUtil.handleException(ex);
    }
}

From source file:fr.chaffottem.bonita.connector.ftp.RemoveDirectoriesConnector.java

private boolean removeDirectory(final String pathDir) throws IOException {
    final FTPFile[] files = getFTPClient().listFiles(pathDir);
    for (final FTPFile file : files) {
        final StringBuilder pathBuilder = new StringBuilder(pathDir);
        pathBuilder.append("/").append(file.getName());
        if (file.isDirectory()) {
            removeDirectory(pathBuilder.toString());
        } else {/*w w w. ja  v  a  2  s.c o m*/
            getFTPClient().deleteFile(pathBuilder.toString());
        }
    }
    return getFTPClient().removeDirectory(pathDir);
}

From source file:ca.ualberta.physics.cssdp.file.remote.protocol.FtpConnection.java

@Override
public List<RemoteFile> ls(String path) {

    logger.debug("Listing files at " + path);

    try {//from www  .j  ava 2  s. com
        ftpClient.enterLocalPassiveMode();
        FTPFile[] files = ftpClient.listFiles(path);

        if (files == null || files.length == 0) {
            return new ArrayList<RemoteFile>();
        }

        List<RemoteFile> list = new ArrayList<RemoteFile>();
        for (FTPFile file : files) {

            String name = file.getName();
            long size = file.getSize();
            boolean isDir = file.isDirectory();
            LocalDateTime modifiedTstamp = new LocalDateTime(file.getTimestamp());

            RemoteFile remoteFile = new RemoteFile("ftp://" + getHostEntry().getHostname() + path + "/" + name,
                    size, modifiedTstamp, isDir);
            list.add(remoteFile);
        }

        return list;

    } catch (SocketTimeoutException timeout) {
        throw new ProtocolException("Timedout listing " + path, true, timeout);

    } catch (IOException e) {
        throw new ProtocolException("Could not get file listing for " + path, false, e);
    }

}

From source file:de.aw.awlib.fragments.AWRemoteFileChooser.java

/**
 * Wird ein Dateieintrag lang ausgewaehlt, wird ein Loeschen-Dialog angeboten.
 *///  w ww .j  a v  a  2  s  . co  m
@Override
public boolean onRecyclerItemLongClick(View v, int position, FTPFile file) {
    if (file.isDirectory()) {
        AWApplication mAppContext = ((AWApplication) getContext().getApplicationContext());
        mUri = withAppendedPath(mUri, file.getName());
        mRemoteFileServer.setMainDirectory(mAppContext, mUri.getEncodedPath());
        if (mRemoteFileServer.isInserted()) {
            mRemoteFileServer.update(getActivity(), mAppContext.getDBHelper());
        } else {
            mRemoteFileServer.insert(getActivity(), mAppContext.getDBHelper());
        }
        mOnActionFinishListener.onActionFinishClicked(layout);
        return true;
    }
    return super.onRecyclerItemLongClick(v, position, file);
}

From source file:com.toolsverse.io.FtpUtils.java

/**
 * Gets the list of FileResource objects from the folder + filename. filename can be a mask, for example: /usr/test/*.txt. 
 * If includeFolders == true recursively includes sub-folders. 
 *
 * @see com.toolsverse.io.FileResource//from w w  w.java  2 s. c o  m
 *
 * @param folder the folder
 * @param filename the filename
 * @param includeFolders the include folders flag. If equals to true recursively includes sub-folders
 * @return the list of FileResource objects
 * @throws Exception in case of any error
 */
public List<FileResource> getFileList(String folder, String filename, boolean includeFolders) throws Exception {
    List<FileResource> remoteFileList = new ArrayList<FileResource>();

    folder = !Utils.isNothing(folder) ? folder : ".";

    FTPFile[] files = ftpClient.listFiles(folder);

    if (files == null || files.length == 0)
        return null;

    for (FTPFile file : files) {
        boolean isDir = file.isDirectory();

        if ((includeFolders || !isDir)
                && FilenameUtils.wildcardMatch(file.getName(), filename, IOCase.INSENSITIVE)) {
            FileResource fileResource = new FileResource();

            if (Utils.isNothing(file.getName()) || "..".equalsIgnoreCase(file.getName())
                    || ".".equalsIgnoreCase(file.getName()))
                continue;

            fileResource.setPath(folder + "/" + file.getName());
            fileResource.setName(file.getName());
            fileResource.setIsDirectory(isDir);
            fileResource.setSize(!isDir ? file.getSize() : 0);
            fileResource
                    .setLastModified(file.getTimestamp() != null ? file.getTimestamp().getTimeInMillis() : 0);

            remoteFileList.add(fileResource);
        }
    }

    return remoteFileList;
}

From source file:de.aw.awlib.fragments.AWRemoteFileChooser.java

/**
 * Wird ein Directory ausgwaehlt, wird in dieses Directory gewechselt.
 *//*w  w  w  .  j  av  a2s .  co  m*/
@Override
public void onRecyclerItemClick(View v, int position, FTPFile file) {
    if (file.isDirectory()) {
        String filename = file.getName();
        if (filename.equals("..")) {
            if (mDirectoyList.size() != 0) {
                mDirectoyList.remove(mDirectoyList.size() - 1);
            }
            mUri = Uri.parse("/");
            for (int i = 0; i < mDirectoyList.size(); i++) {
                String dir = mDirectoyList.get(i);
                mUri = withAppendedPath(mUri, dir);
            }
        } else {
            mDirectoyList.add(filename);
            mUri = withAppendedPath(mUri, filename);
        }
        getExecuter().listFilesInDirectory(mUri.getEncodedPath(), mFileFilter);
    } else {
        super.onRecyclerItemClick(v, position, file);
    }
}

From source file:at.beris.virtualfile.provider.FtpClientFileOperationProvider.java

@Override
public List<at.beris.virtualfile.File> list(FileModel model, Filter filter) throws IOException {
    List<FTPFile> ftpFileList = client.list(resolveUrl(model).getPath());
    List<at.beris.virtualfile.File> fileList = new ArrayList<>();

    String parentPath = model.getUrl().getPath();
    for (FTPFile ftpFile : ftpFileList) {
        FileModel childModel = new FileModel();
        childModel.setParent(model);//from  w w  w. ja  va 2s.  c  om
        String childPath = parentPath + ftpFile.getName() + (ftpFile.isDirectory() ? "/" : "");
        at.beris.virtualfile.File childFile = fileContext.newFile(UrlUtils.newUrl(model.getUrl(), childPath));
        FtpFileTranslator.fillModel(childModel, ftpFile, client);
        childFile.setModel(childModel);
        if (filter == null || filter.filter(childFile)) {
            fileList.add(childFile);
        }
    }
    return fileList;
}

From source file:ch.cyberduck.core.ftp.parser.NTFTPEntryParserTest.java

@Test
public void testParseFieldsOnDirectory() throws Exception {
    FTPFile parsed = parser.parseFTPEntry("12-05-96  05:03PM       <DIR>          absoft2");
    assertNotNull("Could not parse entry.", parsed);
    assertEquals("Thu Dec 05 17:03:00 1996", df.format(parsed.getTimestamp().getTime()));
    assertTrue(parsed.isDirectory());
    assertEquals("absoft2", parsed.getName());

    parsed = parser.parseFTPEntry("12-03-96  06:38AM       <DIR>          123456");
    assertNotNull("Could not parse entry.", parsed);
    assertTrue(parsed.isDirectory());/*from  ww  w .  j av  a2  s  .co  m*/
    assertEquals("123456", parsed.getName());
}

From source file:ilarkesto.integration.ftp.FtpClient.java

public void deleteDir(String path) {
    for (FTPFile file : listFiles(path)) {
        if (file.isDirectory()) {
            deleteDir(path + "/" + file.getName());
        } else {/*w  w  w  .  j  a  va2s.  c o  m*/
            deleteFile(path + "/" + file.getName());
        }
    }
    deleteFile(path);
}

From source file:com.stacksync.desktop.connection.plugins.ftp.FtpTransferManager.java

@Override
public Map<String, RemoteFile> list() throws StorageException {
    connect();/*from w  w w.  j  a v a2  s .c o  m*/

    try {
        Map<String, RemoteFile> files = new HashMap<String, RemoteFile>();
        FTPFile[] ftpFiles = ftp.listFiles(getConnection().getPath());

        for (FTPFile f : ftpFiles) {
            files.put(f.getName(), new RemoteFile(f.getName(), f.getSize(), f));
            if (f.isDirectory()) {
                files.putAll(getDirectoryList(f.getName()));
            }
        }

        return files;
    } catch (IOException ex) {
        logger.error("Unable to list FTP directory.", ex);
        throw new StorageException(ex);
    }
}