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

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

Introduction

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

Prototype

public String getName() 

Source Link

Document

Return the name of the file.

Usage

From source file:br.gov.frameworkdemoiselle.behave.regression.repository.FTPRepository.java

private List<String> findFolders(FTPFile ftpFile) {
    try {//from w w w .jav  a2 s .com
        cd(ftpFile.getName());
        List<String> result = new ArrayList<String>();
        List<FTPFile> files = getFolders();
        if (files.size() == 0) {
            result.add(subPath(ftp.printWorkingDirectory()));
        } else {
            for (FTPFile file : files) {
                for (String path : findFolders(file)) {
                    result.add(path);
                }
            }
        }
        ftp.changeToParentDirectory();
        return result;
    } catch (Exception e) {
        return null;
    }
}

From source file:net.seedboxer.common.ftp.FtpUploaderCommons.java

/**
 * List files inside the current folder.
 * //  w ww  .j a  v  a2  s  . co  m
 * @return List with files names and size
 * @throws IOException
 */
private Map<String, Long> listFiles() throws FtpException {
    int attempts = 0;
    Map<String, Long> files = new LinkedHashMap<String, Long>();
    while (true) {
        try {
            FTPListParseEngine engine = null;
            if (type.startsWith("UNIX")) {
                engine = ftpClient.initiateListParsing(FTPClientConfig.SYST_UNIX, null);
            } else {
                engine = ftpClient.initiateListParsing();
            }

            FTPFile[] list = engine.getFiles();
            if (list != null) {
                for (FTPFile ftpFile : list) {
                    files.put(ftpFile.getName(), ftpFile.getSize());
                }
            }
            return files;
        } catch (Exception e) {
            attempts++;
            if (attempts > 3) {
                throw new FtpListFilesException(e);
            } else {
                LOGGER.trace("First attempt to get list of files FAILED! attempt={}", attempts);
            }
        }
    }
}

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());//  w  w  w .ja  v a2 s  .c o  m
    assertEquals("absoft2", parsed.getName());

    parsed = parser.parseFTPEntry("12-03-96  06:38AM       <DIR>          123456");
    assertNotNull("Could not parse entry.", parsed);
    assertTrue(parsed.isDirectory());
    assertEquals("123456", parsed.getName());
}

From source file:com.bdaum.zoom.ui.internal.wizards.FtpDirPage.java

@Override
protected void validatePage() {
    if (ftp == null) {
        setErrorMessage(Messages.FtpDirPage_no_connection);
        setPageComplete(false);/*  ww w  . j  a v  a 2  s  . c o m*/
        return;
    }
    Object[] checkedElements = viewer.getCheckedElements();
    if (checkedElements.length == 0) {
        setErrorMessage(Messages.FtpDirPage_nothing_selected);
        setPageComplete(false);
        return;
    }
    for (Object object : checkedElements) {
        if (object instanceof FTPFile) {
            FTPFile file = (FTPFile) object;
            if (file.isFile() && filter.accept(file.getName())) {
                setErrorMessage(null);
                setPageComplete(true);
                return;
            }
        }
    }
    setErrorMessage(Messages.FtpDirPage_no_image_is_selected);
    setPageComplete(false);
}

From source file:com.feilong.tools.net.filetransfer.FTPUtil.java

/**
 * Log ftp file.//www.j  a v a2s . c  o  m
 * 
 * @param ftpFile
 *            the ftp file
 */
private void logFTPFile(FTPFile ftpFile) {
    String ftpFileName = ftpFile.getName();
    Object[] params = { ftpFileName, ftpFile.isDirectory(), ftpFile.getType() };
    log.info("ftpFile Name:[{}] ,isDirectory:[{}],ftpFile type:[{}]", params);
}

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

@Test
public void testParseFieldsOnFile() throws Exception {
    FTPFile parsed = parser.parseFTPEntry("05-22-97  12:08AM                  5000000000 AUTOEXEC.BAK");
    assertNotNull("Could not parse entry.", parsed);
    assertEquals("Thu May 22 00:08:00 1997", df.format(parsed.getTimestamp().getTime()));
    assertTrue(parsed.isFile());/*from www  .  j  a va2s .  c  om*/
    assertEquals("AUTOEXEC.BAK", parsed.getName());
    assertEquals(5000000000l, parsed.getSize());
}

From source file:com.github.wuic.nut.ftp.FtpNutDao.java

/**
 * <p>//from w  ww.ja v a2 s .  c  o  m
 * Searches recursively in the given path any files matching the given entry.
 * </p>
 *
 * @param path the path
 * @param pattern the pattern to match
 * @return the list of matching files
 * @throws IOException if the client can't move to a directory or any I/O error occurs
 */
private List<String> recursiveSearch(final String path, final Pattern pattern) throws IOException {
    if (!ftpClient.changeWorkingDirectory(path)) {
        throw new IOException("Can move to the following directory : " + path);
    } else {
        final List<String> retval = new ArrayList<String>();

        // Test each path
        for (final FTPFile file : ftpClient.listFiles()) {
            final Matcher matcher = pattern.matcher(file.getName());

            if (matcher.find()) {
                retval.add(matcher.group());
            }
        }

        // Search in each directory
        for (final FTPFile directory : ftpClient.listDirectories()) {
            final String pwd = ftpClient.printWorkingDirectory();
            retval.addAll(recursiveSearch(directory.getName(), pattern));

            // Remove quotes around the path
            if (pwd.startsWith("\"") && pwd.endsWith("\"")) {
                ftpClient.changeWorkingDirectory(new StringBuilder().append(pwd).deleteCharAt(pwd.length() - 1)
                        .deleteCharAt(0).toString());
            } else {
                ftpClient.changeWorkingDirectory(pwd);
            }
        }

        return retval;
    }
}

From source file:com.bdaum.zoom.ui.internal.wizards.FtpDirPage.java

public URI[] getURIs() {
    if (ftp != null) {
        String prefix = "ftp://" + url.getHost(); //$NON-NLS-1$
        int port = url.getPort();
        if (port > 0 && port != ftp.getDefaultPort())
            prefix += ":" + port; //$NON-NLS-1$
        prefix += '/';
        Object[] checkedElements = viewer.getCheckedElements();
        List<URI> list = new ArrayList<URI>();
        for (Object object : checkedElements) {
            if (object instanceof FTPFile) {
                FTPFile file = (FTPFile) object;
                if (file.isFile() && filter.accept(file.getName())) {
                    FTPFile parent = fileParents.get(file);
                    String dirPath;
                    if (parent == null)
                        dirPath = stripSlashes(dir);
                    else
                        dirPath = stripSlashes(dirPaths.get(parent));
                    try {
                        list.add(new URI(prefix
                                + (dirPath.isEmpty() ? file.getName() : dirPath + '/' + file.getName())));
                    } catch (URISyntaxException e) {
                        // should never happen
                    }/*from  w  w  w. j  a va 2 s .c o m*/
                }
            }
        }
        return list.toArray(new URI[list.size()]);
    }
    return null;
}

From source file:br.gov.frameworkdemoiselle.behave.regression.repository.FTPRepository.java

@Override
public Result getResult(String location, String id) {
    try {//  w ww.ja va 2  s.  co m
        cdHome();
        cd(super.folder);
        cd(location);
        FTPFile[] files;
        String localFolder = tmpFolder + BAR + location;
        files = ftp.listFiles();
        String imageType = null;
        for (FTPFile ftpFile : files) {
            if (ftpFile.getName().startsWith(id + ".")) {
                (new File(localFolder)).mkdirs();
                String extension = FileUtils.getExtension(ftpFile.getName());
                if (!extension.equals("txt")) {
                    imageType = extension;
                }
                FileOutputStream fos = new FileOutputStream(localFolder + BAR + id + "." + extension);
                ftp.setBufferSize(1024);
                ftp.enterLocalPassiveMode();
                ftp.enterLocalActiveMode();
                ftp.retrieveFile(ftpFile.getName(), fos);
                fos.close();
            }
        }
        Result result = new Result();
        result.setLocation(location);
        result.setId(id);
        File detail = new File(localFolder + BAR + id + ".txt");
        if (detail.exists() && detail.isFile()) {
            result.setDetail(FileUtils.readFile(detail));
        }
        if (imageType != null) {
            result.setFile(new File(localFolder + BAR + id + "." + imageType));
        }
        return result;
    } catch (Exception e) {
        return null;
    }
}

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 {//from  w w w .java 2 s .  co  m
            deleteFile(path + "/" + file.getName());
        }
    }
    deleteFile(path);
}