use of org.apache.commons.net.ftp.FTPFile in project Lucee by lucee.
the class FTPResource method setLastModified.
@Override
public boolean setLastModified(long time) {
// if(isRoot()) return false;
FTPResourceClient client = null;
try {
provider.lock(this);
client = provider.getClient(data);
PageContext pc = ThreadLocalPageContext.get();
Calendar c = JREDateTimeUtil.getThreadCalendar();
if (pc != null)
c.setTimeZone(pc.getTimeZone());
c.setTimeInMillis(time);
FTPFile file = client.getFTPFile(this);
if (file == null)
return false;
file.setTimestamp(c);
client.unregisterFTPFile(this);
return true;
} catch (IOException e) {
} finally {
provider.returnClient(client);
provider.unlock(this);
}
return false;
}
use of org.apache.commons.net.ftp.FTPFile in project scheduling by ow2-proactive.
the class FTPConnector method downloadDirectory.
private List<String> downloadDirectory(FTPClient ftpClient, String parentDir, String currentDir, String saveDir) throws IOException {
List<String> filesRelativePathName = new ArrayList<>();
String dirToList = parentDir;
if (!currentDir.isEmpty()) {
dirToList = Paths.get(dirToList, currentDir).toString();
}
FTPFile[] subFiles = ftpClient.listFiles(dirToList);
if (subFiles != null) {
for (FTPFile aFile : subFiles) {
String currentFileName = aFile.getName();
if (currentFileName.equals(".") || currentFileName.equals("..")) {
// skip parent directory and the directory itself
continue;
}
String remoteFilePath = Paths.get(parentDir, currentDir, currentFileName).toString();
String savePath = Paths.get(saveDir, parentDir, currentDir, currentFileName).toString();
if (aFile.isDirectory()) {
// create the directory savePath inside saveDir
makeDirectories(savePath);
// download the sub directory
filesRelativePathName.addAll(downloadDirectory(ftpClient, dirToList, currentFileName, saveDir));
} else {
// download the file
filesRelativePathName.add(downloadSingleFile(ftpClient, remoteFilePath, savePath));
}
}
}
return filesRelativePathName;
}
use of org.apache.commons.net.ftp.FTPFile in project camel by apache.
the class FtpConsumer method doPollDirectory.
protected boolean doPollDirectory(String absolutePath, String dirName, List<GenericFile<FTPFile>> fileList, int depth) {
log.trace("doPollDirectory from absolutePath: {}, dirName: {}", absolutePath, dirName);
depth++;
// remove trailing /
dirName = FileUtil.stripTrailingSeparator(dirName);
// compute dir depending on stepwise is enabled or not
String dir;
if (isStepwise()) {
dir = ObjectHelper.isNotEmpty(dirName) ? dirName : absolutePath;
operations.changeCurrentDirectory(dir);
} else {
dir = absolutePath;
}
log.trace("Polling directory: {}", dir);
List<FTPFile> files = null;
if (isUseList()) {
if (isStepwise()) {
files = operations.listFiles();
} else {
files = operations.listFiles(dir);
}
} else {
// we cannot use the LIST command(s) so we can only poll a named file
// so created a pseudo file with that name
FTPFile file = new FTPFile();
file.setType(FTPFile.FILE_TYPE);
fileExpressionResult = evaluateFileExpression();
if (fileExpressionResult != null) {
file.setName(fileExpressionResult);
files = new ArrayList<FTPFile>(1);
files.add(file);
}
}
if (files == null || files.isEmpty()) {
// no files in this directory to poll
log.trace("No files found in directory: {}", dir);
return true;
} else {
// we found some files
log.trace("Found {} in directory: {}", files.size(), dir);
}
for (FTPFile file : files) {
if (log.isTraceEnabled()) {
log.trace("FtpFile[name={}, dir={}, file={}]", new Object[] { file.getName(), file.isDirectory(), file.isFile() });
}
// check if we can continue polling in files
if (!canPollMoreFiles(fileList)) {
return false;
}
if (file.isDirectory()) {
RemoteFile<FTPFile> remote = asRemoteFile(absolutePath, file, getEndpoint().getCharset());
if (endpoint.isRecursive() && depth < endpoint.getMaxDepth() && isValidFile(remote, true, files)) {
// recursive scan and add the sub files and folders
String subDirectory = file.getName();
String path = absolutePath + "/" + subDirectory;
boolean canPollMore = pollSubDirectory(path, subDirectory, fileList, depth);
if (!canPollMore) {
return false;
}
}
} else if (file.isFile()) {
RemoteFile<FTPFile> remote = asRemoteFile(absolutePath, file, getEndpoint().getCharset());
if (depth >= endpoint.getMinDepth() && isValidFile(remote, false, files)) {
// matched file so add
fileList.add(remote);
}
} else {
log.debug("Ignoring unsupported remote file type: " + file);
}
}
return true;
}
use of org.apache.commons.net.ftp.FTPFile in project camel by apache.
the class FtpOperations method listFiles.
public List<FTPFile> listFiles(String path) throws GenericFileOperationFailedException {
log.trace("listFiles({})", path);
// use current directory if path not given
if (ObjectHelper.isEmpty(path)) {
path = ".";
}
try {
final List<FTPFile> list = new ArrayList<FTPFile>();
FTPFile[] files = client.listFiles(path);
// can return either null or an empty list depending on FTP servers
if (files != null) {
list.addAll(Arrays.asList(files));
}
return list;
} catch (IOException e) {
throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
}
}
use of org.apache.commons.net.ftp.FTPFile in project camel by apache.
the class FtpOperations method listFiles.
public List<FTPFile> listFiles() throws GenericFileOperationFailedException {
log.trace("listFiles()");
try {
final List<FTPFile> list = new ArrayList<FTPFile>();
FTPFile[] files = client.listFiles();
// can return either null or an empty list depending on FTP servers
if (files != null) {
list.addAll(Arrays.asList(files));
}
return list;
} catch (IOException e) {
throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
}
}
Aggregations