use of org.apache.commons.net.ftp.FTPFile in project Lucee by lucee.
the class SFTPClientImpl method listFiles.
@Override
public FTPFile[] listFiles(String pathname) throws IOException {
pathname = cleanPath(pathname);
List<FTPFile> files = new ArrayList<FTPFile>();
try {
Vector list = channelSftp.ls(pathname);
Iterator<ChannelSftp.LsEntry> it = list.iterator();
ChannelSftp.LsEntry entry;
SftpATTRS attrs;
FTPFile file;
String fileName;
while (it.hasNext()) {
entry = it.next();
attrs = entry.getAttrs();
fileName = entry.getFilename();
if (fileName.equals(".") || fileName.equals(".."))
continue;
file = new FTPFile();
files.add(file);
// is dir
file.setType(attrs.isDir() ? FTPFile.DIRECTORY_TYPE : FTPFile.FILE_TYPE);
file.setTimestamp(Caster.toCalendar(attrs.getMTime() * 1000L, null, Locale.ENGLISH));
file.setSize(attrs.isDir() ? 0 : attrs.getSize());
FTPConstant.setPermission(file, attrs.getPermissions());
file.setName(fileName);
}
handleSucess();
} catch (SftpException e) {
handleFail(e, stopOnError);
}
return files.toArray(new FTPFile[files.size()]);
}
use of org.apache.commons.net.ftp.FTPFile in project Lucee by lucee.
the class FTPResource method listResources.
@Override
public Resource[] listResources() {
// new Resource[0];
if (isFile())
return null;
FTPResourceClient client = null;
try {
client = provider.getClient(data);
FTPFile[] files = null;
String p = getInnerPath();
if (!StringUtil.endsWith(p, '/'))
p += "/";
files = client.listFiles(p);
if (files == null)
return new Resource[0];
List list = new ArrayList();
String parent = path.concat(name).concat("/");
String name;
FTPResource res;
for (int i = 0; i < files.length; i++) {
name = files[i].getName();
if (!".".equals(name) && !"..".equals(name)) {
res = new FTPResource(provider, data, parent, name);
client.registerFTPFile(res, files[i]);
list.add(res);
}
}
return (Resource[]) list.toArray(new FTPResource[list.size()]);
} catch (IOException ioe) {
return null;
} finally {
provider.returnClient(client);
}
}
use of org.apache.commons.net.ftp.FTPFile in project Lucee by lucee.
the class FTPResource method hasPermission.
private Boolean hasPermission(int permission) {
FTPResourceClient client = null;
try {
provider.read(this);
client = provider.getClient(data);
FTPFile file = client.getFTPFile(this);
if (file == null)
return null;
return Caster.toBoolean(file.hasPermission(FTPFile.USER_ACCESS, permission) || file.hasPermission(FTPFile.GROUP_ACCESS, permission) || file.hasPermission(FTPFile.WORLD_ACCESS, permission));
} catch (IOException e) {
return Boolean.FALSE;
} finally {
provider.returnClient(client);
}
}
use of org.apache.commons.net.ftp.FTPFile in project Lucee by lucee.
the class FTPResource method exists.
@Override
public boolean exists() {
try {
provider.read(this);
} catch (IOException e) {
return true;
}
FTPResourceClient client = null;
InputStream is = null;
try {
// getClient has to be first to check connection
client = provider.getClient(data);
if (isRoot())
return true;
FTPFile file = client.getFTPFile(this);
if (file != null) {
return !file.isUnknown();
}
// String pathname = getInnerPath();
String p = getInnerPath();
if (!StringUtil.endsWith(p, '/'))
p += "/";
if (client.listNames(p) != null)
return true;
return false;
} catch (IOException e) {
return false;
} finally {
IOUtil.closeEL(is);
provider.returnClient(client);
}
}
use of org.apache.commons.net.ftp.FTPFile in project Lucee by lucee.
the class FTPResource method setMode.
@Override
public void setMode(int mode) throws IOException {
// if(isRoot()) throw new IOException("can't change mode of root");
FTPResourceClient client = null;
try {
provider.lock(this);
client = provider.getClient(data);
FTPFile file = client.getFTPFile(this);
if (file != null) {
// World
file.setPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION, (mode & 01) > 0);
file.setPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION, (mode & 02) > 0);
file.setPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION, (mode & 04) > 0);
// Group
file.setPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION, (mode & 010) > 0);
file.setPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION, (mode & 020) > 0);
file.setPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION, (mode & 040) > 0);
// Owner
file.setPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION, (mode & 0100) > 0);
file.setPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION, (mode & 0200) > 0);
file.setPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION, (mode & 0400) > 0);
client.unregisterFTPFile(this);
}
} catch (IOException e) {
} finally {
provider.returnClient(client);
provider.unlock(this);
}
}
Aggregations