【发布时间】:2018-01-10 04:19:08
【问题描述】:
我有本地服务器 mockftpserver,在服务器中有几个文件,它们用前缀“._”保护,防止获取这些文件的方法如下:
protected String getRealPath(Session session, String path) {
String currentDirectory = (String) session.getAttribute(SessionKeys.CURRENT_DIRECTORY);
String result;
if (path == null) {
result = currentDirectory;
}
else if (getFileSystem().isAbsolute(path)) {
result = path;
}
else {
result = getFileSystem().path(currentDirectory, path);
}
return result.replace("._", "");
}
我试图列出我得到的 FTP 服务器中的文件,但我看不到受保护的文件,如“._passwrd”。 我用正常的方法获取文件列表:
boolean login = ftpClient.login("user", "password");
if (login) {
System.out.println("Connection established...");
FTPFile[] files = ftpClient.listFiles();
for (FTPFile file : files) {
if (file.getType() == FTPFile.FILE_TYPE) {
System.out.println("File Name: "
+ file.getName()
+ " File Size: " );
}
}
String[] fil = ftpClient.listNames();
if (files != null && fil.length > 0) {
for (String aFile: fil) {
System.out.println(aFile);
}
}
BufferedReader reader = null;
String firstLine = null;
try {
InputStream stream =
ftpClient.retrieveFileStream("._"+"._passwd");
reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
firstLine = reader.readLine();
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException logOrIgnore) {}
}
}
但认为该方法只会检查一次名称,所以如果我再次添加 ._ 它应该可以工作。尽管它没有或我无法以正确的方式应用它。
【问题讨论】:
-
你找到答案了吗?