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:org.martin.ftp.net.FTPLinker.java

public void delete(FTPFile file, Type type) throws IOException {

    String path = getWorkingDirectory() + "/" + file.getName();

    if (type == Type.FILE)
        client.deleteFile(path);//w  w  w  . j a va  2  s  .c o  m
    else
        client.removeDirectory(path);
}

From source file:org.martin.ftp.net.FTPLinker.java

public void rename(FTPFile file, String newName) throws IOException {
    client.rename(file.getName(), newName);
    System.out.println(getReplyCode());
}

From source file:org.martin.ftp.util.RemoteComparator.java

@Override
public int compare(FTPFile o1, FTPFile o2) {

    if (null != option)
        switch (option) {
        case DATE:
            if (order == SortOption.UPWARD)
                return (int) (o1.getTimestamp().getTimeInMillis() - o2.getTimestamp().getTimeInMillis());

            else//from w  w w .j a  v a 2s . c  o m
                return (int) (o2.getTimestamp().getTimeInMillis() - o1.getTimestamp().getTimeInMillis());

        case FORMAT:
            String file1Format = Utilities.getFormat(o1.getName());
            String file2Format = Utilities.getFormat(o2.getName());
            if (order == SortOption.UPWARD)
                if (o1.isDirectory() || o2.isDirectory()) {
                    if (o1.isDirectory() && o2.isDirectory())
                        return idDirectory - idDirectory;
                    else if (o1.isDirectory() && !o2.isDirectory())
                        return idDirectory - idFile;
                    else
                        return idFile - idDirectory;
                } else
                    return file1Format.compareToIgnoreCase(file2Format);
            else if (o1.isDirectory() || o2.isDirectory()) {
                if (o1.isDirectory() && o2.isDirectory())
                    return idDirectory - idDirectory;
                else if (o1.isDirectory() && !o2.isDirectory())
                    return idFile - idDirectory;
                else
                    return idDirectory - idFile;
            } else
                return file2Format.compareToIgnoreCase(file1Format);

        case NAME:
            if (order == SortOption.UPWARD)
                return o1.getName().compareToIgnoreCase(o2.getName());
            else
                return o2.getName().compareToIgnoreCase(o1.getName());

        case SIZE:
            if (order == SortOption.UPWARD)
                return (int) (o1.getSize() - o2.getSize());
            else
                return (int) (o2.getSize() - o1.getSize());

        case TYPE:
            if ((o1.isDirectory() && o2.isDirectory()) || (!o1.isDirectory() && !o2.isDirectory()))
                return idDirectory - idDirectory;

            if (order == SortOption.UPWARD)
                if (o1.isDirectory() && !o2.isDirectory())
                    return idDirectory - idFile;

                else
                    return idFile - idDirectory;
            else if (o1.isDirectory() && !o2.isDirectory())
                return idFile - idDirectory;

            else
                return idDirectory - idFile;
        default:
            return 0;
        }

    return 0;
}

From source file:org.martin.ftp.util.SearchComparator.java

@Override
public int compare(FileFiltering o1, FileFiltering o2) {

    FTPFile fileO1 = o1.getFile();
    FTPFile fileO2 = o2.getFile();/* ww w.ja  v  a 2  s  .  c om*/

    if (null != option)
        switch (option) {
        case DATE:
            if (order == SortOption.UPWARD)
                return (int) (fileO1.getTimestamp().getTimeInMillis()
                        - fileO2.getTimestamp().getTimeInMillis());

            else
                return (int) (fileO2.getTimestamp().getTimeInMillis()
                        - fileO1.getTimestamp().getTimeInMillis());

        case FORMAT:
            String file1Format = Utilities.getFormat(fileO1.getName());
            String file2Format = Utilities.getFormat(fileO2.getName());
            if (order == SortOption.UPWARD)
                if (fileO1.isDirectory() || fileO2.isDirectory()) {
                    if (fileO1.isDirectory() && fileO2.isDirectory())
                        return idDirectory - idDirectory;
                    else if (fileO1.isDirectory() && !fileO2.isDirectory())
                        return idDirectory - idFile;
                    else
                        return idFile - idDirectory;
                } else
                    return file1Format.compareToIgnoreCase(file2Format);
            else if (fileO1.isDirectory() || fileO2.isDirectory()) {
                if (fileO1.isDirectory() && fileO2.isDirectory())
                    return idDirectory - idDirectory;
                else if (fileO1.isDirectory() && !fileO2.isDirectory())
                    return idFile - idDirectory;
                else
                    return idDirectory - idFile;
            } else
                return file2Format.compareToIgnoreCase(file1Format);

        case NAME:
            if (order == SortOption.UPWARD)
                return fileO1.getName().compareToIgnoreCase(fileO2.getName());
            else
                return fileO2.getName().compareToIgnoreCase(fileO1.getName());

        case SIZE:
            if (order == SortOption.UPWARD)
                return (int) (fileO1.getSize() - fileO2.getSize());
            else
                return (int) (fileO2.getSize() - fileO1.getSize());

        case TYPE:
            if ((fileO1.isDirectory() && fileO2.isDirectory())
                    || (!fileO1.isDirectory() && !fileO2.isDirectory()))
                return idDirectory - idDirectory;

            if (order == SortOption.UPWARD)
                if (fileO1.isDirectory() && !fileO2.isDirectory())
                    return idDirectory - idFile;

                else
                    return idFile - idDirectory;
            else if (fileO1.isDirectory() && !fileO2.isDirectory())
                return idFile - idDirectory;

            else
                return idDirectory - idFile;
        default:
            return 0;
        }

    return 0;
}

From source file:org.mcisb.util.io.FtpClient.java

/**
 * /*from ww  w  . ja  v  a 2  s.  c  om*/
 * @param directory
 * @return List<String>
 * @throws IOException
 */
public List<String> getFilenames(final String directory) throws IOException {
    final List<String> filenames = new ArrayList<>();
    client.changeWorkingDirectory(directory);
    check();

    for (FTPFile file : client.listFiles()) {
        filenames.add(file.getName());
    }

    return filenames;
}

From source file:org.mockftpserver.stub.StubFtpServerIntegrationTest.java

/**
 * Verify that the FTPFile has the specified properties
 * /*from  w  ww . j ava2s  . co m*/
 * @param ftpFile - the FTPFile to verify
 * @param type - the expected file type
 * @param name - the expected file name
 * @param size - the expected file size (will be zero for a directory)
 */
private void verifyFTPFile(FTPFile ftpFile, int type, String name, long size) {
    LOG.info(ftpFile);
    assertEquals("type: " + ftpFile, type, ftpFile.getType());
    assertEquals("name: " + ftpFile, name, ftpFile.getName());
    assertEquals("size: " + ftpFile, size, ftpFile.getSize());
}

From source file:org.mousephenotype.dcc.crawler.FtpCrawler.java

private ZipFile retrieveOrCreateZipFile(FilenameTokenizer t, FTPFile f) {
    DatabaseAccessor da = DatabaseAccessor.getInstance();
    String filename = f.getName();
    ZipFile z = da.getZipFile(filename);
    if (z == null) {
        FilenameTokens tokens = t.tokenize(filename);
        z = new ZipFile(filename);
        if (tokens != null) {
            z.setCentreId(tokens.getProducer());
            z.setCreated(tokens.getCreated());
            z.setInc(tokens.getInc());//from ww w. ja v  a2 s  .c  om
            z.setSizeBytes(f.getSize());
        }
        da.persist(z);
    }
    return z;
}

From source file:org.mousephenotype.dcc.crawler.ZipFileFilter.java

@Override
public boolean accept(FTPFile f) {
    return f != null && f.isFile() && f.getName().endsWith(".zip");
}

From source file:org.mule.transport.ftp.FtpMessageReceiver.java

@Override
public void poll() throws Exception {
    FTPFile[] files = listFiles();/* w  ww  .ja  va  2 s .c o  m*/
    if (logger.isDebugEnabled()) {
        logger.debug("Poll encountered " + files.length + " new file(s)");
    }

    synchronized (scheduledFiles) {
        for (final FTPFile file : files) {
            if (getLifecycleState().isStopping()) {
                break;
            }

            final String fileName = file.getName();

            if (!scheduledFiles.contains(fileName) && !currentFiles.contains(fileName)) {
                if (!scheduledFiles.contains(fileName) && !currentFiles.contains(fileName)) {
                    scheduledFiles.add(fileName);
                    getWorkManager().scheduleWork(new FtpWork(fileName, file));
                }
            }
        }
    }
}

From source file:org.mule.transport.ftp.FtpMessageReceiver.java

protected FTPFile[] listFiles() throws Exception {
    FTPClient client = null;/*from  w w  w.ja  va  2s  .com*/
    try {
        client = connector.createFtpClient(endpoint);
        FTPListParseEngine engine = client.initiateListParsing();
        FTPFile[] files = null;
        List<FTPFile> v = new ArrayList<FTPFile>();
        while (engine.hasNext()) {
            if (getLifecycleState().isStopping()) {
                break;
            }
            files = engine.getNext(FTP_LIST_PAGE_SIZE);
            if (files == null || files.length == 0) {
                return files;
            }
            for (FTPFile file : files) {
                if (file.isFile()) {
                    if (filenameFilter == null || filenameFilter.accept(null, file.getName())) {
                        v.add(file);
                    }
                }
            }
        }

        if (!FTPReply.isPositiveCompletion(client.getReplyCode())) {
            throw new IOException("Failed to list files. Ftp error: " + client.getReplyCode());
        }

        return v.toArray(new FTPFile[v.size()]);
    } finally {
        if (client != null) {
            connector.releaseFtp(endpoint.getEndpointURI(), client);
        }
    }
}