mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
修复exist分隔符结尾判断错误的问题
This commit is contained in:
parent
4852d67bed
commit
feb62498fd
@ -2,6 +2,7 @@ package cn.hutool.extra.ftp;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
@ -96,6 +97,15 @@ public abstract class AbstractFtp implements Closeable {
|
||||
* @return 是否存在
|
||||
*/
|
||||
public boolean exist(String path) {
|
||||
// 目录验证
|
||||
if (isDir(path)) {
|
||||
return true;
|
||||
} else {
|
||||
if (CharUtil.isFileSeparator(path.charAt(path.length() - 1))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 文件验证
|
||||
final String fileName = FileUtil.getName(path);
|
||||
final String dir = StrUtil.removeSuffix(path, fileName);
|
||||
final List<String> names;
|
||||
|
@ -100,4 +100,37 @@ public class FtpTest {
|
||||
Console.log(ftp.pwd());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void existSftpTest() throws Exception {
|
||||
try (Sftp ftp = new Sftp("127.0.0.1", 22, "test", "test")) {
|
||||
Console.log(ftp.pwd());
|
||||
Console.log(ftp.exist("/home/test"));
|
||||
Console.log(ftp.exist("/home/test/"));
|
||||
Console.log(ftp.exist("/home/test//////"));
|
||||
Console.log(ftp.exist("/home/test/file1"));
|
||||
Console.log(ftp.exist("/home/test/file1/"));
|
||||
Console.log(ftp.exist("///////////"));
|
||||
Console.log(ftp.exist("./"));
|
||||
Console.log(ftp.exist("./file1"));
|
||||
Console.log(ftp.pwd());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@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("/file1"));
|
||||
Console.log(ftp.exist("/file1/"));
|
||||
Console.log(ftp.exist("///////////"));
|
||||
Console.log(ftp.exist("./"));
|
||||
Console.log(ftp.exist("./file1"));
|
||||
Console.log(ftp.pwd());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user