Search in sources :

Example 1 with FTPPath

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

the class Ftp method existsDir.

private boolean existsDir(AFTPClient client, String strPath) throws PageException, IOException {
    strPath = strPath.trim();
    // get parent path
    FTPPath path = new FTPPath(client, strPath);
    String p = path.getPath();
    String n = path.getName();
    strPath = p + "" + n;
    if ("//".equals(p))
        strPath = "/" + n;
    if (!strPath.endsWith("/"))
        strPath += "/";
    return client.directoryExists(directory);
}
Also used : FTPPath(lucee.runtime.net.ftp.FTPPath)

Example 2 with FTPPath

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

the class Ftp method existsFile.

/* *
     * check if file or directory exists if it exists return FTPFile otherwise null
     * @param client
     * @param strPath
     * @return FTPFile or null
     * @throws IOException
     * @throws PageException
     * /
    private FTPFile exists(FTPClient client, String strPath) throws PageException, IOException {
        strPath=strPath.trim();
        
        // get parent path
        FTPPath path=new FTPPath(client.printWorkingDirectory(),strPath);
        String name=path.getName();
        print.out("path:"+name);
        
        // when directory
        FTPFile[] files=null;
        try {
            files = client.listFiles(path.getPath());
        } catch (IOException e) {}
        
        if(files!=null) {
            for(int i=0;i<files.length;i++) {
                if(files[i].getName().equalsIgnoreCase(name)) {
                    return files[i];
                }
            }
            
        }
        return null;
    }*/
private FTPFile existsFile(AFTPClient client, String strPath, boolean isFile) throws PageException, IOException {
    strPath = strPath.trim();
    if (strPath.equals("/")) {
        FTPFile file = new FTPFile();
        file.setName("/");
        file.setType(FTPFile.DIRECTORY_TYPE);
        return file;
    }
    // get parent path
    FTPPath path = new FTPPath(client, strPath);
    String p = path.getPath();
    String n = path.getName();
    strPath = p;
    if ("//".equals(p))
        strPath = "/";
    if (isFile)
        strPath += n;
    // when directory
    FTPFile[] files = null;
    try {
        files = client.listFiles(p);
    } catch (IOException e) {
    }
    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            if (files[i].getName().equalsIgnoreCase(n)) {
                return files[i];
            }
        }
    }
    return null;
}
Also used : FTPFile(org.apache.commons.net.ftp.FTPFile) IOException(java.io.IOException) FTPPath(lucee.runtime.net.ftp.FTPPath)

Aggregations

FTPPath (lucee.runtime.net.ftp.FTPPath)2 IOException (java.io.IOException)1 FTPFile (org.apache.commons.net.ftp.FTPFile)1