use of org.apache.commons.net.ftp.FTPFile in project Lucee by lucee.
the class Ftp method removeRecursive.
private static void removeRecursive(AFTPClient client, String path, int type) throws IOException {
// directory
if (FTPFile.DIRECTORY_TYPE == type) {
if (!path.endsWith("/"))
path += "/";
// first we remove the children
FTPFile[] children = client.listFiles(path);
for (FTPFile child : children) {
if (child.getName().equals(".") || child.getName().equals(".."))
continue;
removeRecursive(client, path + child.getName(), child.getType());
}
// then the directory itself
client.removeDirectory(path);
} else // file
if (FTPFile.FILE_TYPE == type) {
client.deleteFile(path);
}
}
use of org.apache.commons.net.ftp.FTPFile 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;
}
use of org.apache.commons.net.ftp.FTPFile in project Lucee by lucee.
the class Ftp method actionExistsFile.
/**
* check if a file exists or not
* @return FTPCLient
* @throws IOException
* @throws PageException
*/
private AFTPClient actionExistsFile() throws PageException, IOException {
required("remotefile", remotefile);
AFTPClient client = getClient();
FTPFile file = existsFile(client, remotefile, true);
Struct cfftp = writeCfftp(client);
cfftp.setEL(RETURN_VALUE, Caster.toBoolean(file != null && file.isFile()));
cfftp.setEL(SUCCEEDED, Boolean.TRUE);
stoponerror = false;
return client;
}
use of org.apache.commons.net.ftp.FTPFile in project Lucee by lucee.
the class Ftp method actionExists.
/**
* check if a file or directory exists
* @return FTPCLient
* @throws PageException
* @throws IOException
*/
private AFTPClient actionExists() throws PageException, IOException {
required("item", item);
AFTPClient client = getClient();
FTPFile file = existsFile(client, item, false);
Struct cfftp = writeCfftp(client);
cfftp.setEL(RETURN_VALUE, Caster.toBoolean(file != null));
cfftp.setEL(SUCCEEDED, Boolean.TRUE);
return client;
}
use of org.apache.commons.net.ftp.FTPFile in project Lucee by lucee.
the class Ftp method actionListDir.
/**
* List data of a ftp connection
* @return FTPCLient
* @throws PageException
* @throws IOException
*/
private AFTPClient actionListDir() throws PageException, IOException {
required("name", name);
required("directory", directory);
AFTPClient client = getClient();
FTPFile[] files = client.listFiles(directory);
if (files == null)
files = new FTPFile[0];
pageContext.setVariable(name, toQuery(files, "ftp", directory, client.getRemoteAddress().getHostName()));
writeCfftp(client);
return client;
}
Aggregations