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.jaeksoft.searchlib.crawler.file.process.fileInstances.FtpFileInstance.java

protected FtpFileInstance(FilePathItem filePathItem, FtpFileInstance parent, FTPFile ftpFile)
        throws URISyntaxException, SearchLibException, UnsupportedEncodingException {
    init(filePathItem, parent, LinkUtils.concatPath(parent.getPath(), ftpFile.getName()));
    this.ftpFile = ftpFile;
}

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

@Override
public List<Result> getResulstByLocation(String location) {
    try {/*w ww  .j a va  2  s .  co  m*/
        cdHome();
        cd(super.folder);
        cd(location);
        List<String> ids = new ArrayList<String>();
        for (FTPFile file : ftp.listFiles()) {
            if (FileUtils.getExtension(file.getName()).equalsIgnoreCase("txt")) {
                ids.add(file.getName().substring(0, file.getName().length() - 4));
            }
        }
        Collections.sort(ids);
        List<Result> r = new ArrayList<Result>();
        for (String id : ids) {
            Result result = getResult(location, id);
            if (result != null) {
                r.add(result);
            }
        }
        return r;

    } catch (Exception e) {
        throw new BehaveException(e);
    }
}

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

@Override
protected Map<String, FileInfoEntity> getLsFileMap(String remotePath) throws Exception {
    Map<String, FileInfoEntity> map = new HashMap<String, FileInfoEntity>();
    FTPFile[] ftpFiles = ftpClient.listFiles(remotePath);
    for (FTPFile ftpFile : ftpFiles) {

        String filename = ftpFile.getName();

        boolean isDirectory = ftpFile.isDirectory();

        FileInfoEntity fileEntity = new FileInfoEntity();
        fileEntity.setFileType(isDirectory ? FileType.DIRECTORY : FileType.FILE);
        fileEntity.setName(filename);//from www. j  a  v  a2s .  c  om
        fileEntity.setSize(ftpFile.getSize());
        fileEntity.setLastModified(ftpFile.getTimestamp().getTimeInMillis());

        map.put(filename, fileEntity);
    }
    return map;
}

From source file:com.toolsverse.io.FtpUtils.java

/**
 * Gets the list of FileResource objects from the folder + filename. filename can be a mask, for example: /usr/test/*.txt. 
 * If includeFolders == true recursively includes sub-folders. 
 *
 * @see com.toolsverse.io.FileResource//  w w w.  j  av a  2s. c  o m
 *
 * @param folder the folder
 * @param filename the filename
 * @param includeFolders the include folders flag. If equals to true recursively includes sub-folders
 * @return the list of FileResource objects
 * @throws Exception in case of any error
 */
public List<FileResource> getFileList(String folder, String filename, boolean includeFolders) throws Exception {
    List<FileResource> remoteFileList = new ArrayList<FileResource>();

    folder = !Utils.isNothing(folder) ? folder : ".";

    FTPFile[] files = ftpClient.listFiles(folder);

    if (files == null || files.length == 0)
        return null;

    for (FTPFile file : files) {
        boolean isDir = file.isDirectory();

        if ((includeFolders || !isDir)
                && FilenameUtils.wildcardMatch(file.getName(), filename, IOCase.INSENSITIVE)) {
            FileResource fileResource = new FileResource();

            if (Utils.isNothing(file.getName()) || "..".equalsIgnoreCase(file.getName())
                    || ".".equalsIgnoreCase(file.getName()))
                continue;

            fileResource.setPath(folder + "/" + file.getName());
            fileResource.setName(file.getName());
            fileResource.setIsDirectory(isDir);
            fileResource.setSize(!isDir ? file.getSize() : 0);
            fileResource
                    .setLastModified(file.getTimestamp() != null ? file.getTimestamp().getTimeInMillis() : 0);

            remoteFileList.add(fileResource);
        }
    }

    return remoteFileList;
}

From source file:au.org.intersect.dms.wn.transports.impl.FtpConnection.java

private FileInfo makeFileInfo(String parentPath, FTPFile info) {
    Date date = info.getTimestamp().getTime();
    int ftpType = info.getType();
    if (ftpType == FTPFile.SYMBOLIC_LINK_TYPE) {
        try {/*from   w w w .  j  av  a 2s .  co  m*/
            changeWorkingDirectory(PathUtils.joinPath(parentPath, info.getName()));
            ftpType = FTPFile.DIRECTORY_TYPE;
        } catch (IOException e) {
            throw new TransportException("Cannot get list directory (" + info.getName() + ")");
        } catch (PathNotFoundException e) {
            ftpType = FTPFile.FILE_TYPE;
        }
    }
    FileType type = ftpType == FTPFile.DIRECTORY_TYPE ? FileType.DIRECTORY : FileType.FILE;
    FileInfo item = new FileInfo(type, PathUtils.joinPath(parentPath, info.getName()), info.getName(),
            info.getSize(), date);
    return item;
}

From source file:com.moosemorals.mediabrowser.FtpScanner.java

private void scrapeFTP() throws IOException {
    synchronized (ftp) {
        connect();//from   www . j a v a  2s  .co m
        List<PVRFolder> queue = new LinkedList<>();
        queue.add((PVRFolder) pvr.getRoot());

        int total = 0;
        int checked = 0;

        while (!queue.isEmpty() && !ftpThread.isInterrupted()) {
            PVRFolder directory = queue.remove(0);
            if (!ftp.changeWorkingDirectory(FTP_ROOT + directory.getRemotePath())) {
                throw new IOException("Can't change FTP directory to " + FTP_ROOT + directory.getRemotePath());
            }

            FTPFile[] fileList = ftp.listFiles();
            total += fileList.length;
            for (FTPFile f : fileList) {
                if (f.getName().equals(".") || f.getName().equals("..")) {
                    // skip entries for this directory and parent directory
                    total -= 1;
                    continue;
                }
                if (f.isDirectory()) {
                    PVRFolder next = pvr.addFolder(directory, f.getName());
                    next.setFtpScanned(true);
                    pvr.updateItem(next);
                    queue.add(next);
                } else if (f.isFile() && f.getName().endsWith(".ts")) {
                    PVRFile file = pvr.addFile(directory, f.getName());
                    file.setSize(f.getSize());
                    updateFromHMT(file);
                    pvr.updateItem(file);
                }
                checked += 1;
                notifyScanListeners(DeviceListener.ScanType.ftp, total, checked);
            }
        }
        disconnect();
    }
}

From source file:com.moosemorals.mediabrowser.FtpScanner.java

/**
 * Triggers a DLNA server rescan (on the PVR). Skips a lot of checks on the
 * assumption that its called from unlock only.
 *
 * @param target//from   w  ww.j  ava 2s .c o m
 */
private void renameInPlace(PVRFile target) throws IOException {

    String basename = FilenameUtils.getBaseName(target.getRemoteFilename());

    for (FTPFile f : ftp.listFiles()) {
        String oldName = f.getName();
        if (basename.equals(FilenameUtils.getBaseName(oldName))) {

            String extension = FilenameUtils.getExtension(oldName);

            String newName;
            if (basename.endsWith("-")) {
                newName = basename.substring(0, basename.length() - 1) + extension;
            } else {
                newName = basename + "-." + extension;
            }

            log.debug("Moving {} to {} ", oldName, newName);

            if (!ftp.rename(oldName, newName)) {
                throw new IOException("Can't rename " + target.getRemoteFilename());
            }

            if (extension.equals("ts")) {
                target.setRemoteFilename(newName);
            }

        }
    }

}

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/*w w w.  ja  v a  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.moosemorals.mediabrowser.FtpScanner.java

public void moveToFolder(List<PVRFile> files, PVRFolder destination) throws IOException {
    synchronized (ftp) {
        boolean connected = connect();

        for (PVRFile target : files) {
            if (!ftp.changeWorkingDirectory(FTP_ROOT + target.getParent().getRemotePath())) {
                throw new IOException(
                        "Can't change FTP directory to " + FTP_ROOT + target.getParent().getRemotePath());
            }/*  www.  j a v a  2  s.c  o  m*/

            String basename = FilenameUtils.getBaseName(target.getRemoteFilename());

            for (FTPFile f : ftp.listFiles()) {
                String oldName = f.getName();
                if (basename.equals(FilenameUtils.getBaseName(oldName))) {

                    String newName = FTP_ROOT + destination.getRemotePath() + oldName;

                    log.debug("Moving {} to {} ", oldName, newName);

                    if (!ftp.rename(oldName, newName)) {
                        throw new IOException("Can't rename " + target.getRemoteFilename());
                    }

                    if (FilenameUtils.getExtension(oldName).equals("ts")) {
                        target.setRemoteFilename(newName);
                    }
                }
            }

            pvr.updateItem(target);
        }

        if (connected) {
            disconnect();
        }
    }
}

From source file:de.aw.awlib.fragments.AWRemoteFileChooser.java

/**
 * Wird ein Dateieintrag lang ausgewaehlt, wird ein Loeschen-Dialog angeboten.
 *//*from www. ja v  a  2 s .  c om*/
@Override
public boolean onRecyclerItemLongClick(View v, int position, FTPFile file) {
    if (file.isDirectory()) {
        AWApplication mAppContext = ((AWApplication) getContext().getApplicationContext());
        mUri = withAppendedPath(mUri, file.getName());
        mRemoteFileServer.setMainDirectory(mAppContext, mUri.getEncodedPath());
        if (mRemoteFileServer.isInserted()) {
            mRemoteFileServer.update(getActivity(), mAppContext.getDBHelper());
        } else {
            mRemoteFileServer.insert(getActivity(), mAppContext.getDBHelper());
        }
        mOnActionFinishListener.onActionFinishClicked(layout);
        return true;
    }
    return super.onRecyclerItemLongClick(v, position, file);
}