diff --git a/hutool-extra/src/main/java/cn/hutool/extra/ftp/AbstractFtp.java b/hutool-extra/src/main/java/cn/hutool/extra/ftp/AbstractFtp.java
index 245cf0955..fbc08871a 100644
--- a/hutool-extra/src/main/java/cn/hutool/extra/ftp/AbstractFtp.java
+++ b/hutool-extra/src/main/java/cn/hutool/extra/ftp/AbstractFtp.java
@@ -195,7 +195,7 @@ public abstract class AbstractFtp implements Closeable {
* @param file 需要上传的文件
* @return 是否成功
*/
- public abstract boolean upload(String destPath, File file);
+ public abstract boolean uploadFile(String destPath, File file);
/**
* 下载文件
diff --git a/hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java b/hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java
index 7d02f8420..50623cc28 100755
--- a/hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java
+++ b/hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java
@@ -269,10 +269,11 @@ public class Ftp extends AbstractFtp {
/**
* 是否执行完操作返回当前目录
+ *
* @return 执行完操作是否返回当前目录
* @since 5.7.17
*/
- public boolean isBackToPwd(){
+ public boolean isBackToPwd() {
return this.backToPwd;
}
@@ -340,7 +341,7 @@ public class Ftp extends AbstractFtp {
* 遍历某个目录下所有文件和目录,不会递归遍历
* 此方法自动过滤"."和".."两种目录
*
- * @param path 目录
+ * @param path 目录
* @param predicate 过滤器,null表示不过滤,默认去掉"."和".."两种目录
* @return 文件或目录列表
* @since 5.3.5
@@ -408,6 +409,7 @@ public class Ftp extends AbstractFtp {
*
* @param path 路径
* @return 状态int,服务端不同,返回不同
+ * @throws IORuntimeException IO异常
* @since 5.4.3
*/
public int stat(final String path) throws IORuntimeException {
@@ -491,39 +493,42 @@ public class Ftp extends AbstractFtp {
* 上传文件到指定目录,可选:
*
*
- * 1. destPath为null或""上传到当前路径 - * 2. destPath为相对路径则相对于当前路径的子路径 - * 3. destPath为绝对路径则上传到此路径 + * 1. remotePath为null或""上传到当前路径 + * 2. remotePath为相对路径则相对于当前路径的子路径 + * 3. remotePath为绝对路径则上传到此路径 ** - * @param destPath 服务端路径,可以为{@code null} 或者相对路径或绝对路径 - * @param file 文件 + * @param remotePath 服务端路径,可以为{@code null} 或者相对路径或绝对路径 + * @param file 文件 * @return 是否上传成功 */ @Override - public boolean upload(final String destPath, final File file) { + public boolean uploadFile(final String remotePath, final File file) { Assert.notNull(file, "file to upload is null !"); - return upload(destPath, file.getName(), file); + if (false == FileUtil.isFile(file)) { + throw new FtpException("[{}] is not a file!", file); + } + return uploadFile(remotePath, file.getName(), file); } /** * 上传文件到指定目录,可选: * *
- * 1. destPath为null或""上传到当前路径 - * 2. destPath为相对路径则相对于当前路径的子路径 - * 3. destPath为绝对路径则上传到此路径 + * 1. remotePath为null或""上传到当前路径 + * 2. remotePath为相对路径则相对于当前路径的子路径 + * 3. remotePath为绝对路径则上传到此路径 ** - * @param file 文件 - * @param destPath 服务端路径,可以为{@code null} 或者相对路径或绝对路径 - * @param fileName 自定义在服务端保存的文件名 + * @param file 文件 + * @param remotePath 服务端路径,可以为{@code null} 或者相对路径或绝对路径 + * @param fileName 自定义在服务端保存的文件名 * @return 是否上传成功 * @throws IORuntimeException IO异常 */ - public boolean upload(final String destPath, final String fileName, final File file) throws IORuntimeException { + public boolean uploadFile(final String remotePath, final String fileName, final File file) throws IORuntimeException { try (final InputStream in = FileUtil.getInputStream(file)) { - return upload(destPath, fileName, in); + return uploadFile(remotePath, fileName, in); } catch (final IOException e) { throw new IORuntimeException(e); } @@ -533,18 +538,18 @@ public class Ftp extends AbstractFtp { * 上传文件到指定目录,可选: * *
- * 1. destPath为null或""上传到当前路径 - * 2. destPath为相对路径则相对于当前路径的子路径 - * 3. destPath为绝对路径则上传到此路径 + * 1. remotePath为null或""上传到当前路径 + * 2. remotePath为相对路径则相对于当前路径的子路径 + * 3. remotePath为绝对路径则上传到此路径 ** - * @param destPath 服务端路径,可以为{@code null} 或者相对路径或绝对路径 + * @param remotePath 服务端路径,可以为{@code null} 或者相对路径或绝对路径 * @param fileName 文件名 * @param fileStream 文件流 * @return 是否上传成功 * @throws IORuntimeException IO异常 */ - public boolean upload(final String destPath, final String fileName, final InputStream fileStream) throws IORuntimeException { + public boolean uploadFile(final String remotePath, final String fileName, final InputStream fileStream) throws IORuntimeException { try { client.setFileType(FTPClient.BINARY_FILE_TYPE); } catch (final IOException e) { @@ -556,10 +561,10 @@ public class Ftp extends AbstractFtp { pwd = pwd(); } - if (StrUtil.isNotBlank(destPath)) { - mkDirs(destPath); - if (false == cd(destPath)) { - throw new FtpException("Change dir to [{}] error, maybe dir not exist!", destPath); + if (StrUtil.isNotBlank(remotePath)) { + mkDirs(remotePath); + if (false == cd(remotePath)) { + throw new FtpException("Change dir to [{}] error, maybe dir not exist!", remotePath); } } @@ -574,6 +579,41 @@ public class Ftp extends AbstractFtp { } } + /** + * 递归上传文件(支持目录)