ftp.exist分支优化

This commit is contained in:
yebukong 2022-08-31 14:14:08 +08:00
parent feb62498fd
commit f279b4a9ac
2 changed files with 13 additions and 6 deletions

View File

@ -100,13 +100,15 @@ public abstract class AbstractFtp implements Closeable {
// 目录验证
if (isDir(path)) {
return true;
} else {
if (CharUtil.isFileSeparator(path.charAt(path.length() - 1))) {
return false;
}
}
if (CharUtil.isFileSeparator(path.charAt(path.length() - 1))) {
return false;
}
final String fileName = FileUtil.getName(path);
if (".".equals(fileName) || "..".equals(fileName)) {
return false;
}
// 文件验证
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
final List<String> names;
try {

View File

@ -122,14 +122,19 @@ public class FtpTest {
@Ignore
public void existFtpTest() throws Exception {
try (Ftp ftp = new Ftp("127.0.0.1", 21)) {
Console.log(ftp.exist("/test/"));
Console.log(ftp.exist("/test"));
Console.log(ftp.exist("/test/"));
Console.log(ftp.exist("/test//////"));
Console.log(ftp.exist("/test/.."));
Console.log(ftp.exist("/test/."));
Console.log(ftp.exist("/file1"));
Console.log(ftp.exist("/file1/"));
Console.log(ftp.exist("///////////"));
Console.log(ftp.exist("./"));
Console.log(ftp.exist("./file1"));
Console.log(ftp.exist("."));
Console.log(ftp.exist("./2/3/4/.."));
Console.log(ftp.ls("./2/3/4/.."));
Console.log(ftp.pwd());
}
}