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:nl.nn.adapterframework.filesystem.FtpFileSystem.java

@Override
public OutputStream appendFile(FTPFile f) throws FileSystemException, IOException {
    OutputStream outputStream = ftpClient.appendFileStream(f.getName());
    return completePendingCommand(outputStream);
}

From source file:nl.nn.adapterframework.filesystem.FtpFileSystem.java

@Override
public InputStream readFile(FTPFile f) throws FileSystemException, IOException {
    InputStream inputStream = ftpClient.retrieveFileStream(f.getName());
    ftpClient.completePendingCommand();//w  w  w  .jav a 2 s .  c o m
    return inputStream;
}

From source file:nl.nn.adapterframework.filesystem.FtpFileSystem.java

@Override
public void deleteFile(FTPFile f) throws FileSystemException {
    try {/*from   w  w w  .jav  a2 s.  c o  m*/
        ftpClient.deleteFile(f.getName());
    } catch (IOException e) {
        throw new FileSystemException(e);
    }
}

From source file:nl.nn.adapterframework.filesystem.FtpFileSystem.java

@Override
public void createFolder(FTPFile f) throws FileSystemException {
    if (exists(f)) {
        throw new FileSystemException(
                "Create directory for [" + f.getName() + "] has failed. Directory already exists.");
    }/*from w w  w  .  ja  v a  2s.  co m*/
    try {
        ftpClient.makeDirectory(f.getName());
    } catch (IOException e) {
        throw new FileSystemException(e);
    }
}

From source file:nl.nn.adapterframework.filesystem.FtpFileSystem.java

@Override
public void removeFolder(FTPFile f) throws FileSystemException {
    if (!exists(f)) {
        throw new FileSystemException(
                "Remove directory for [" + f.getName() + "] has failed. Directory does not exist.");
    }// w ww.  java  2s .  com
    try {
        ftpClient.removeDirectory(f.getName());
    } catch (IOException e) {
        throw new FileSystemException(e);
    }
}

From source file:nl.nn.adapterframework.filesystem.FtpFileSystem.java

@Override
public void renameTo(FTPFile f, String destination) throws FileSystemException {
    if (exists(toFile(destination))) {
        throw new FileSystemException("Cannot rename file. Destination file already exists.");
    }//from   w ww. j a  va  2 s .co  m
    try {
        ftpClient.rename(f.getName(), destination);
    } catch (IOException e) {
        throw new FileSystemException(e);
    }
}

From source file:nl.nn.adapterframework.filesystem.FtpFileSystem.java

@Override
public String getName(FTPFile f) throws FileSystemException {
    return f.getName();
}

From source file:nl.nn.adapterframework.filesystem.FtpFileSystem.java

@Override
public String getCanonicalName(FTPFile f, boolean isFolder) throws FileSystemException {
    return f.getName();
}

From source file:nl.nn.adapterframework.filesystem.FtpFileSystem.java

@Override
public Date getModificationTime(FTPFile f, boolean isFolder) throws FileSystemException {
    try {/*from   w  w  w . j  ava  2  s. c  o m*/
        return ftpClient.listFiles(f.getName())[0].getTimestamp().getTime();
    } catch (IndexOutOfBoundsException oobe) {
        throw new FileSystemException("File could not be found", oobe);
    } catch (IOException e) {
        throw new FileSystemException("Could not retrieve file", e);
    }
}

From source file:no.imr.sea2data.core.util.FTPUtil.java

/**
 * Download a whole directory from a FTP server.
 *
 * @param ftpClient an instance of org.apache.commons.net.ftp.FTPClient
 * class./*w  w  w.j a v a  2  s  . c o m*/
 * @param remoteParentDir Path of the parent directory of the current directory
 * being downloaded.
 * @param currentDir Path of the current directory being downloaded.
 * @param localParentDir path of directory where the whole remote directory will be
 * downloaded and saved.
 * @throws IOException if any network or IO error occurred.
 */
public static void retrieveDir(FTPClient ftpClient, String remoteParentDir, String localParentDir)
        throws IOException {
    FTPFile[] ftpFiles = ftpClient.listFiles(remoteParentDir);
    if (ftpFiles == null || ftpFiles.length == 0) {
        return;
    }
    for (FTPFile ftpFile : ftpFiles) {
        String ftpFileName = ftpFile.getName();
        if (ftpFileName.equals(".") || ftpFileName.equals("..")) {
            // skip parent directory and the directory itself
            continue;
        }
        String localFile = localParentDir + "/" + ftpFileName;
        String remoteFile = remoteParentDir + "/" + ftpFileName;
        if (ftpFile.isDirectory()) {
            // create the directory in saveDir
            File newDir = new File(localFile);
            newDir.mkdirs();
            // download the sub directory
            retrieveDir(ftpClient, remoteFile, localFile);
        } else {
            // download the file
            retrieveFile(ftpClient, remoteFile, localFile);
        }
    }
}