Search in sources :

Example 16 with AFTPClient

use of lucee.runtime.net.ftp.AFTPClient in project Lucee by lucee.

the class Ftp method actionGetFile.

/**
 * gets a file from server and copy it local
 * @return FTPCLient
 * @throws PageException
 * @throws IOException
 */
private AFTPClient actionGetFile() throws PageException, IOException {
    required("remotefile", remotefile);
    required("localfile", localfile);
    AFTPClient client = getClient();
    // new File(localfile);
    Resource local = ResourceUtil.toResourceExistingParent(pageContext, localfile);
    pageContext.getConfig().getSecurityManager().checkFileLocation(local);
    if (failifexists && local.exists())
        throw new ApplicationException("File [" + local + "] already exist, if you want to overwrite, set attribute failIfExists to false");
    OutputStream fos = null;
    client.setFileType(getType(local));
    boolean success = false;
    try {
        fos = IOUtil.toBufferedOutputStream(local.getOutputStream());
        success = client.retrieveFile(remotefile, fos);
    } finally {
        IOUtil.closeEL(fos);
        if (!success)
            local.delete();
    }
    writeCfftp(client);
    return client;
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) AFTPClient(lucee.runtime.net.ftp.AFTPClient) OutputStream(java.io.OutputStream) Resource(lucee.commons.io.res.Resource)

Aggregations

AFTPClient (lucee.runtime.net.ftp.AFTPClient)16 Struct (lucee.runtime.type.Struct)6 FTPFile (org.apache.commons.net.ftp.FTPFile)3 Resource (lucee.commons.io.res.Resource)2 ApplicationException (lucee.runtime.exp.ApplicationException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 FTPConnection (lucee.runtime.net.ftp.FTPConnection)1