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:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java

public void testUnknownTimestampFormat() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(//from  w ww.j ava2 s .co m
            "-rw-rw-rw- 1 hoerspiel hoerspiel  3722053 19. Sep 13:24 Offenbarung 23 - Menschenopfer - 02.mp3");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "Offenbarung 23 - Menschenopfer - 02.mp3");

    parsed = parser.parseFTPEntry(
            "-rw-rw-rw- 1 hoerspiel hoerspiel 10128531 19. Sep 13:24 Offenbarung 23 - Menschenopfer - 01.mp3");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "Offenbarung 23 - Menschenopfer - 01.mp3");
    parsed = parser.parseFTPEntry(
            "-rw-rw-rw- 1 hoerspiel hoerspiel 11714687 19. Sep 13:25 Offenbarung 23 - Menschenopfer - 08.mp3");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "Offenbarung 23 - Menschenopfer - 08.mp3");

    parsed = parser.parseFTPEntry("-rw-r--r--   1 www-data www-data      10089849 Dec 20 09:30 Stone Catalog");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "Stone Catalog");
    assertEquals(parsed.getUser(), "www-data");
    assertEquals(parsed.getGroup(), "www-data");
    assertEquals(parsed.getSize(), 10089849);

    parsed = parser.parseFTPEntry(
            "-rw-r--r--   1 www-data www-data      34524204 Dec 20 13:41 Winter 2008 Newsletter.sit");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "Winter 2008 Newsletter.sit");
    assertEquals(parsed.getUser(), "www-data");
    assertEquals(parsed.getGroup(), "www-data");
    assertEquals(parsed.getSize(), 34524204);
}

From source file:com.nononsenseapps.filepicker.sample.ftp.FtpPickerFragment.java

/**
 * Get a loader that lists the files in the current path,
 * and monitors changes.//from  ww  w .  j  a v a  2s .  co  m
 */
@NonNull
@Override
public Loader<SortedList<FtpFile>> getLoader() {
    return new AsyncTaskLoader<SortedList<FtpFile>>(getContext()) {
        @Override
        public SortedList<FtpFile> loadInBackground() {
            SortedList<FtpFile> sortedList = new SortedList<>(FtpFile.class,
                    new SortedListAdapterCallback<FtpFile>(getDummyAdapter()) {
                        @Override
                        public int compare(FtpFile lhs, FtpFile rhs) {
                            if (lhs.isDirectory() && !rhs.isDirectory()) {
                                return -1;
                            } else if (rhs.isDirectory() && !lhs.isDirectory()) {
                                return 1;
                            } else {
                                return lhs.getName().compareToIgnoreCase(rhs.getName());
                            }
                        }

                        @Override
                        public boolean areContentsTheSame(FtpFile oldItem, FtpFile newItem) {
                            return oldItem.getName().equals(newItem.getName());
                        }

                        @Override
                        public boolean areItemsTheSame(FtpFile item1, FtpFile item2) {
                            return item1.getName().equals(item2.getName());
                        }
                    });

            if (!ftp.isConnected()) {
                // Connect
                try {
                    ftp.connect(server, port);

                    ftp.setFileType(FTP.ASCII_FILE_TYPE);
                    ftp.enterLocalPassiveMode();
                    ftp.setUseEPSVwithIPv4(false);

                    if (!(loggedIn = ftp.login(username, password))) {
                        ftp.logout();
                        Log.e(TAG, "Login failed");
                    }
                } catch (IOException e) {
                    if (ftp.isConnected()) {
                        try {
                            ftp.disconnect();
                        } catch (IOException ignored) {
                        }
                    }
                    Log.e(TAG, "Could not connect to server.");
                }
            }

            if (loggedIn) {
                try {
                    // handle if directory does not exist. Fall back to root.
                    if (mCurrentPath == null || !mCurrentPath.isDirectory()) {
                        mCurrentPath = getRoot();
                    }

                    sortedList.beginBatchedUpdates();
                    for (FTPFile f : ftp.listFiles(mCurrentPath.getPath())) {
                        FtpFile file;
                        if (f.isDirectory()) {
                            file = new FtpDir(mCurrentPath, f.getName());
                        } else {
                            file = new FtpFile(mCurrentPath, f.getName());
                        }
                        if (isItemVisible(file)) {
                            sortedList.add(file);
                        }
                    }
                    sortedList.endBatchedUpdates();
                } catch (IOException e) {
                    Log.e(TAG, "IOException: " + e.getMessage());
                }
            }

            return sortedList;
        }

        /**
         * Handles a request to start the Loader.
         */
        @Override
        protected void onStartLoading() {
            super.onStartLoading();

            // handle if directory does not exist. Fall back to root.
            if (mCurrentPath == null || !mCurrentPath.isDirectory()) {
                mCurrentPath = getRoot();
            }

            forceLoad();
        }
    };
}

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

/**
 * http://trac.cyberduck.ch/ticket/1076//w w  w  .  ja v  a  2s.co  m
 *
 * @
 */
@Test
public void testSizeWithIndicator() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry("-rw-rw-rw- 1 ftp operator 9.0M Mar 22 17:44 Cyberduck-2.7.3.dmg");
    assertNotNull(parsed);
    assertTrue(parsed.isFile());
    assertEquals("Cyberduck-2.7.3.dmg", parsed.getName());
    assertEquals((long) (9.0 * 1048576), parsed.getSize());
    assertEquals(parsed.getUser(), "ftp");
    assertEquals(parsed.getGroup(), "operator");
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(22, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));

    parsed = parser.parseFTPEntry("-rw-rw-rw- 1 ftp operator 61.8M Mar 7 18:42 GC Wayfinding pics.zip ");
    assertNotNull(parsed);
    assertTrue(parsed.isFile());
    assertEquals((long) (61.8 * 1048576), parsed.getSize());
    assertEquals("ftp", parsed.getUser());
    assertEquals("operator", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(7, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));

    parsed = parser.parseFTPEntry("-rw-rw-rw- 1 ftp operator 172.4k Mar 7 16:01 HEALY071.TXT ");
    assertNotNull(parsed);
    assertTrue(parsed.isFile());
    assertEquals((long) (172.4 * 1024), parsed.getSize());
    assertEquals(parsed.getUser(), "ftp");
    assertEquals(parsed.getGroup(), "operator");
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(7, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}

From source file:com.clickha.nifi.processors.util.FTPTransferV2.java

@Override
public FileInfo getRemoteFileInfo(final FlowFile flowFile, String path, String remoteFileName)
        throws IOException {
    final FTPClient client = getClient(flowFile);

    if (path == null) {
        int slashpos = remoteFileName.lastIndexOf('/');
        if (slashpos >= 0 && !remoteFileName.endsWith("/")) {
            path = remoteFileName.substring(0, slashpos);
            remoteFileName = remoteFileName.substring(slashpos + 1);
        } else {//from   w ww .  ja v  a2  s.  c  om
            path = "";
        }
    }

    final FTPFile[] files = client.listFiles(path);
    FTPFile matchingFile = null;
    for (final FTPFile file : files) {
        if (file.getName().equalsIgnoreCase(remoteFileName)) {
            matchingFile = file;
            break;
        }
    }

    if (matchingFile == null) {
        return null;
    }

    return newFileInfo(matchingFile, path);
}

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

/**
 * http://trac.cyberduck.ch/ticket/143//from w  w w.j  a v  a  2  s  .c  om
 */
@Test
public void testLeadingWhitespace() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry("-rw-r--r--   1 20708    205         3553312 Feb 18 2005  D3I0_515.fmr");
    assertNotNull(parsed);
    assertTrue(parsed.isFile());
    assertEquals("D3I0_515.fmr", parsed.getName());
    assertEquals("20708", parsed.getUser());
    assertEquals("205", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.FEBRUARY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(18, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(2005, parsed.getTimestamp().get(Calendar.YEAR));

    parsed = parser.parseFTPEntry("drwxr-sr-x  14 17037    209            4096 Oct  6 2000  v3r7");
    assertNotNull(parsed);
    assertTrue(parsed.isDirectory());
    assertEquals("v3r7", parsed.getName());
    assertEquals("17037", parsed.getUser());
    assertEquals("209", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(6, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(2000, parsed.getTimestamp().get(Calendar.YEAR));

    // #2895
    parsed = parser.parseFTPEntry("-rwx------ 1 user group          38635 Jul 13 2006  users.xml");
    assertNotNull(parsed);
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals("users.xml", parsed.getName());
    assertEquals("user", parsed.getUser());
    assertEquals("group", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.JULY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(13, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(2006, parsed.getTimestamp().get(Calendar.YEAR));
}

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

@Test
public void testWindowsNTSystem() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("Windows_NT version 5.0");

    FTPFile parsed;

    // #5505// w  w w .j a  v  a  2s.  c o m
    parsed = parser.parseFTPEntry(
            "drwxrwxrwx   1 owner    group               0 Dec  5  0:45 adele.handmadebyflloyd.com");
    assertNotNull(parsed);
    assertEquals("adele.handmadebyflloyd.com", parsed.getName());
    assertEquals("owner", parsed.getUser());
    assertEquals("group", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.DECEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(5, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));

    // #5505
    parsed = parser.parseFTPEntry("drwxrwxrwx   1 owner    group               0 Jan 22  2009 contact");
    assertNotNull(parsed);
    assertEquals("contact", parsed.getName());
    assertEquals("owner", parsed.getUser());
    assertEquals("group", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.JANUARY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(22, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(2009, parsed.getTimestamp().get(Calendar.YEAR));
}

From source file:com.datos.vfs.provider.ftp.FtpFileObject.java

/**
 * Lists the children of the file.//w  w  w . j av a  2 s  . c o m
 */
@Override
protected String[] doListChildren() throws Exception {
    // List the children of this file
    doGetChildren();

    // VFS-210
    if (children == null) {
        return null;
    }

    // TODO - get rid of this children stuff
    final String[] childNames = new String[children.size()];
    int childNum = -1;
    final Iterator<FTPFile> iterChildren = children.values().iterator();
    while (iterChildren.hasNext()) {
        childNum++;
        final FTPFile child = iterChildren.next();
        childNames[childNum] = child.getName();
    }

    return UriParser.encode(childNames);
}

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

@Test
public void testMVSParser() {
    FTPFileEntryParser parser = new FTPParserSelector()
            .getParser("MVS is the operating system of this server. FTP Server is running on z/OS.");

    FTPFile parsed;

    final String entry = "drwxr-xr-x   6 START2   SYS1        8192 Oct 28  2008 ADCD";
    parser.preParse(new ArrayList<String>(Arrays.asList("total 66", entry)));
    // #7717//from  w  w  w. jav  a 2 s. com
    parsed = parser.parseFTPEntry(entry);
    assertNotNull(parsed);
    assertEquals("ADCD", parsed.getName());
    assertEquals("START2", parsed.getUser());
    assertEquals("SYS1", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(28, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(2008, parsed.getTimestamp().get(Calendar.YEAR));
}

From source file:com.adaptris.ftp.ApacheFtpClientImpl.java

/**
 * list files in the current server directory
 *//*from  w w  w . j a va 2s .  c  om*/
@Override
public String[] dir(String dirname, boolean full) throws IOException {
    String[] listing = new String[0];
    try {
        acquireLock();
        log("{} {}", FTPCmd.LIST, dirname);
        FTPFile[] results = ftpClient().listFiles(dirname);
        logReply(ftpClient().getReplyStrings());
        List<String> output = new ArrayList<String>();
        for (FTPFile file : results) {
            if (full) {
                output.add(file.toFormattedString());
            } else {
                output.add(file.getName());
            }
            listing = output.toArray(new String[output.size()]);
        }
    } finally {
        releaseLock();
    }
    return listing;
}

From source file:it.greenvulcano.util.file.RegExFileFilter.java

public boolean accept(FTPFile file) {
    boolean fileTypeMatches = false;
    boolean nameMatches = false;
    boolean isModified = false;

    boolean isFile = !file.isDirectory();
    fileTypeMatches = ((fileType == ALL) || ((fileType == FILES_ONLY) && isFile)
            || ((fileType == DIRECTORIES_ONLY) && !isFile));

    if (fileTypeMatches) {
        if (pattern != null) {
            Matcher m = pattern.matcher(file.getName());
            nameMatches = m.matches();/* w ww .  j a v  a  2s .  c  o  m*/
        } else {
            nameMatches = true;
        }

        if (nameMatches) {
            if (checkLastModified) {
                isModified = selectModifiedSince ? (file.getTimestamp().getTimeInMillis() > lastTimestamp)
                        : (file.getTimestamp().getTimeInMillis() <= lastTimestamp);
            } else {
                isModified = true;
            }
        }
    }

    return fileTypeMatches && nameMatches && isModified;
}