add method

This commit is contained in:
Looly
2021-02-18 16:04:07 +08:00
parent 4405d7b8f9
commit f104eb8ecc
5 changed files with 231 additions and 195 deletions

View File

@@ -82,7 +82,12 @@ public abstract class AbstractFtp implements Closeable {
public boolean exist(String path) {
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
final List<String> names = ls(dir);
final List<String> names;
try{
names = ls(dir);
} catch (FtpException ignore){
return false;
}
return containsIgnoreCase(names, fileName);
}

View File

@@ -346,7 +346,7 @@ public class Ftp extends AbstractFtp {
if (StrUtil.isNotBlank(path)) {
pwd = pwd();
if(false == cd(path)){
throw new FtpException("Change dir to [{}] error, maybe path not exist!");
throw new FtpException("Change dir to [{}] error, maybe path not exist!", path);
}
}
@@ -410,7 +410,7 @@ public class Ftp extends AbstractFtp {
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
if(false == cd(dir)){
throw new FtpException("Change dir to [{}] error, maybe dir not exist!");
throw new FtpException("Change dir to [{}] error, maybe dir not exist!", path);
}
boolean isSuccess;
@@ -528,7 +528,7 @@ public class Ftp extends AbstractFtp {
if (StrUtil.isNotBlank(path)) {
mkDirs(path);
if (false == cd(path)) {
throw new FtpException("Change dir to [{}] error, maybe dir not exist!");
throw new FtpException("Change dir to [{}] error, maybe dir not exist!", path);
}
}
@@ -636,7 +636,7 @@ public class Ftp extends AbstractFtp {
}
if(false == cd(path)){
throw new FtpException("Change dir to [{}] error, maybe dir not exist!");
throw new FtpException("Change dir to [{}] error, maybe dir not exist!", path);
}
if (null != fileNameCharset) {