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:com.eryansky.common.utils.ftp.FtpFactory.java

/**
 * FTP?.//from  w  w  w  . ja va 2  s.  co  m
 * 
 * @param remotePath
 *            FTP?
 * @param fileName
 *            ???
 * @param localPath
 *            ??
 * @return
 */
public boolean ftpDownFile(String remotePath, String fileName, String localPath) {
    // ?
    boolean success = false;
    // FTPClient
    FTPClient ftp = new FTPClient();
    ftp.setControlEncoding("GBK");
    try {
        int reply;
        // FTP?
        // ??ftp.connect(url)?FTP?
        ftp.connect(url, port);
        // ftp
        ftp.login(username, password);
        reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            return success;
        }
        // 
        ftp.changeWorkingDirectory(remotePath);
        // 
        FTPFile[] fs = ftp.listFiles();
        // ??
        for (FTPFile ff : fs) {
            if (ff.getName().equals(fileName)) {
                // ???
                File localFile = new File(localPath + "/" + ff.getName());
                // ?
                OutputStream is = new FileOutputStream(localFile);
                // 
                ftp.retrieveFile(ff.getName(), is);
                is.close();
                success = true;
            }
        }
        ftp.logout();
        // ?

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException ioe) {
            }
        }
    }
    return success;
}

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

/**
 * http://trac.cyberduck.ch/ticket/1198/*w w w.  j a va 2s .  c om*/
 */
@Test
public void testFile() {
    FTPFile parsed;

    parsed = parser.parseFTPEntry("-r--r--r--          0     165100     165100 Aug  1 10:24 grau2.tif");
    assertNotNull(parsed);
    assertEquals("grau2.tif", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(Calendar.AUGUST, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(1, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(10, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY));
    assertEquals(24, parsed.getTimestamp().get(Calendar.MINUTE));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}

From source file:ftpclient.FTPManager.java

public FTPFile[] getCurrentDirectoryFilesList() throws IOException {
    if (client.isConnected()) {
        FTPFile[] fs = client.listFiles();
        //listFiles returns both files and directories!
        List<FTPFile> fsList = new ArrayList<>();
        for (FTPFile f : fs) {
            if (f.isFile()) {
                fsList.add(f);/*from   www. ja va  2  s .com*/
            }
        }
        Collections.sort(fsList, new Comparator<FTPFile>() {

            @Override
            public int compare(FTPFile o1, FTPFile o2) {
                return o1.getName().compareToIgnoreCase(o2.getName());
            }

        });

        return (FTPFile[]) fsList.toArray(new FTPFile[] {});
    } else {
        return null;
    }
}

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

/**
 * http://trac.cyberduck.ch/ticket/1198/*from  www  .  j  ava  2  s .  c om*/
 */
@Test
public void testFolder() {
    FTPFile parsed;

    parsed = parser.parseFTPEntry("dr--r--r--                folder          0 Aug  1 10:18 TestCyberduck");
    assertNotNull(parsed);
    assertEquals("TestCyberduck", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals(Calendar.AUGUST, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(1, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(10, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY));
    assertEquals(18, parsed.getTimestamp().get(Calendar.MINUTE));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}

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

/**
 * #5573// ww w .j a  v a 2 s. c o m
 */
@Test
public void testListingWithAbsolutePaths() {
    FTPFile parsed;

    parsed = parser.parseFTPEntry(
            "- [RWCEAFMS] Petersm                             0 May 05  2004 /data/FTP_pub/WelcomeTo_PeakFTP");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "/data/FTP_pub/WelcomeTo_PeakFTP");
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
}

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

private void checkBtnActionPerformed() {
    try {/* w w  w.  ja va 2  s .c  om*/
        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:com.nostra13.universalimageloader.core.download.BaseImageDownloader.java

public FTPFile getFile(FTPFile[] ftpFiles, String name) {
    FTPFile musicFile = new FTPFile();
    for (FTPFile file : ftpFiles) {
        if (file.getName().equals(name)) {
            musicFile = file;/*w w w .  ja v  a  2s  .co  m*/
        }
    }
    return musicFile;
}

From source file:de.idos.updates.install.FtpFileInstaller.java

@Override
public void installElement(FTPFile element, Version version) throws IOException {
    if (ftpClient == null) {
        return;/*from   w  w w . j  av a  2 s  . co  m*/
    }
    ftpClient.changeWorkingDirectory(version.asString());
    report.installingFile(element.getName());
    DataImport dataImport = new DataImport().reportProgressTo(report);
    FtpFileDataInVersion dataInVersion = new FtpFileDataInVersion(ftpClient, element, dataImport);
    installation.addContent(dataInVersion);
    ftpClient.changeToParentDirectory();
}

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

@Test
public void testUnknownSystIdentifier() throws Exception {
    this.parser = new FTPParserSelector().getParser("Digital Domain FTP");

    FTPFile parsed;
    parsed = parser.parseFTPEntry("drwxrwxrwx               folder        0 Jan 19 20:36 Mastered 1644");
    assertNotNull(parsed);/* w ww .  j  a  v  a2 s.  c  o m*/
    assertEquals("Mastered 1644", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());

    parsed = parser.parseFTPEntry("-rwxrwxrwx        0   208143684 208143684 Jan 14 02:13 Dhannya dhannya.rar");
    assertNotNull(parsed);
    assertEquals("Dhannya dhannya.rar", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());

    parsed = parser.parseFTPEntry("drwxr-xr-x               folder        0 Jan 14 16:04 Probeordner");
    assertNotNull(parsed);
    assertEquals("Probeordner", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
}

From source file:fr.lille1.car.burihabwa.rest.utils.FTPAdapterImpl.java

@Override
public boolean isDirectory(final String path) throws IOException {
    if (path == null) {
        throw new IllegalArgumentException("path argument cannot be null!");
    }/*from   ww  w.j a  v  a2s .  co m*/
    if (!this.client.isConnected()) {
        this.authenticate();
    }
    Path filePath = Paths.get(path);
    int nameCount = filePath.getNameCount();
    FTPFile[] directories = this.client.listDirectories();
    for (FTPFile directory : directories) {
        if (directory.getName().equalsIgnoreCase(path)) {
            return true;
        }
    }
    return false;
}