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

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

Introduction

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

Prototype

public boolean isFile() 

Source Link

Document

Determine if the file is a regular file.

Usage

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

@Override
public boolean exists(final String path) throws IOException {
    if (!this.client.isConnected()) {
        this.authenticate();
    }/*from  ww w  . j  a v a 2  s  . co  m*/
    String parentDirectory = getParentDirectory(path);
    String file = getFile(path);
    if (!this.client.changeWorkingDirectory(parentDirectory)) {
        return false;
    }

    FTPFile[] files = this.client.listFiles();
    for (FTPFile f : files) {
        if (f.isFile() && f.getName().equalsIgnoreCase(file)) {
            this.client.changeWorkingDirectory("");
            return true;
        }
    }
    this.client.changeWorkingDirectory("");
    return false;
}

From source file:com.atomicleopard.thundr.ftp.FtpSession.java

public boolean getFile(FTPFile file, OutputStream os) {
    return file != null && file.isFile() && getFile(file.getName(), os);
}

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());
    assertEquals("AUTOEXEC.BAK", parsed.getName());
    assertEquals(5000000000l, parsed.getSize());
}

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);/*from www .  j  a  va2  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.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 v  a  2 s  . c  o m
                }
            }
        }
        return list.toArray(new URI[list.size()]);
    }
    return null;
}

From source file:com.connection.factory.FtpConnectionApacheLib.java

@Override
public void readAllFilesInCurrentPathWithListener(FileListener listener, String remotePath) {

    try {//from w  ww  .j a  v  a2  s . co m
        FTPFile[] fileListTemp = _ftpObj.listFiles(remotePath);
        for (FTPFile each : fileListTemp) {
            RemoteFileObject objectTemp = null;
            if (each.isFile()) {
                objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE);
                objectTemp.setFileName(each.getName());
                objectTemp.setAbsolutePath(remotePath);
                objectTemp.setFileSize(each.getSize());
                objectTemp.setFileType();
                objectTemp.setDate(each.getTimestamp().getTime());
                listener.handleRemoteFile(objectTemp);
            }
        }
    } catch (IOException | ConnectionException ex) {

    }

}

From source file:cn.zhuqi.mavenssh.web.util.FtpUtil.java

/**
 * Lists the files in the given FTP directory.
 *
 * @param filePath absolute path on the server
 * @return files relative names list//from w  w w . j  a  va 2 s . c o m
 * @throws IOException on I/O errors
 */
public List<String> list(String filePath) throws IOException {
    List<String> fileList = new ArrayList<String>();

    // Use passive mode to pass firewalls.
    ftp.enterLocalPassiveMode();

    FTPFile[] ftpFiles = ftp.listFiles(filePath);
    int size = (ftpFiles == null) ? 0 : ftpFiles.length;
    for (int i = 0; i < size; i++) {
        FTPFile ftpFile = ftpFiles[i];
        if (ftpFile.isFile()) {
            fileList.add(ftpFile.getName());
        }
    }

    return fileList;
}

From source file:com.connection.factory.FtpConnectionApacheLib.java

@Override
public List<RemoteFileObject> readAllFilesInCurrentPath(String remotePath) {
    List<RemoteFileObject> willReturnObject = new ArrayList<>();
    try {// w  w w.  ja  v a 2 s  .  c  om
        FTPFile[] fileListTemp = _ftpObj.listFiles(remotePath);
        for (FTPFile each : fileListTemp) {
            RemoteFileObject objectTemp = null;
            if (each.isFile()) {

                objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE);
                //  System.out.println(each);
                objectTemp.setFileName(each.getName());
                objectTemp.setAbsolutePath(remotePath);
                objectTemp.setFileSize(each.getSize());
                objectTemp.setFileType();
                objectTemp.setDate(each.getTimestamp().getTime());
                willReturnObject.add(objectTemp);
            }
        }
    } catch (IOException | ConnectionException ex) {
        return null;
    }
    return willReturnObject.isEmpty() ? null : willReturnObject;
}

From source file:com.example.lista3new.SyncService.java

private void syncFiles(final String ftpDir, final String localDir) {
    Log.d(TAG, "Curr:" + ftpGetCurrentDirectory() + ":" + ftpDir + "|");
    File dir = new File(localDir);
    if (!dir.exists()) {
        dir.mkdirs();//from  w  w w  . j a  v a2s.c om
    }
    if (!ftpGetCurrentDirectory().equals(ftpDir)) {
        ftpChangeDirectory(ftpDir);
    }
    Log.d(TAG, "ftpDir: " + ftpDir);
    Log.d(TAG, "localDir: " + localDir);
    List<FTPFile> ftpFiles = ftpGetFileList(ftpDir);
    List<File> localFiles = getLocalFileList(localDir);
    for (int i = 0; i < ftpFiles.size(); ++i) {
        FTPFile file = ftpFiles.get(i);
        String fileName = file.getName();
        File localFile = new File(localDir + "/" + fileName);
        if (file.isFile()) {
            Log.d(TAG, "file: " + fileName);
            if (!localFile.exists()) {
                ftpDownloadFile(ftpDir + "/" + fileName, localDir + "/" + fileName);
                sendFileDownloadedMessage(localDir, fileName, FILE_TYPE);
            }

        } else if (file.isDirectory() && !fileName.equals(".") && !fileName.equals("..")) {
            boolean addToList = !localFile.exists();
            Log.d(TAG, "dir: " + fileName);
            syncFiles(ftpDir + "/" + file.getName(), localDir + "/" + file.getName());
            if (addToList) {
                sendFileDownloadedMessage(localDir, fileName, DIR_TYPE);
            }
        }

    }
    for (int i = 0; i < localFiles.size(); ++i) {
        File file = localFiles.get(i);
        String fileName = file.getName();
        Log.d(TAG, "Found local file:" + localDir + "/" + file.getName());
        if (file.isFile() && !ftpFileExists(ftpDir + "/" + fileName)) {
            Log.d(TAG, "Uploading to: " + ftpDir + "/" + file.getName());
            ftpUpload(localDir + "/" + file.getName(), ftpDir + "/" + file.getName());
        } else if (file.isDirectory() && !ftpDirExists(ftpDir + "/" + fileName)) {
            ftpMakeDirectory(ftpDir + "/" + file.getName());
            // synFiles
        }

    }

}

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

private int countAndRemove(FTPFile ftpFile, boolean remove) {
    int result = 0;
    try {/*www.  j a v a  2  s  .  c o  m*/
        if (ftpFile.isFile()) {
            if (remove && !ftp.deleteFile(ftpFile.getName())) {
                throw new BehaveException(message.getString("exception-erro-remove-file", ftpFile.getName()));
            }
            if (FileUtils.getExtension(ftpFile.getName()).equals("txt")) {
                return 1;
            } else {
                return 0;
            }
        } else {
            if (ftp.changeWorkingDirectory(ftpFile.getName())) {
                FTPFile[] files = ftp.listFiles();
                for (FTPFile _ftpFile : files) {
                    result += countAndRemove(_ftpFile, remove);
                }
                if (!ftp.changeToParentDirectory()) {
                    throw new BehaveException(message.getString("exception-erro-change-folder", ".."));
                }
                if (remove && !ftp.removeDirectory(ftpFile.getName())) {
                    throw new BehaveException(
                            message.getString("exception-erro-remove-folder", ftpFile.getName()));
                }
            } else {
                throw new BehaveException(message.getString("exception-erro-change-folder", ftpFile.getName()));
            }
        }
    } catch (Exception e) {
        throw new BehaveException(e);
    }
    return result;
}