mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
hutool-extra ftp 支持上传文件或目录
This commit is contained in:
parent
df139f8ab7
commit
ec5965f49c
@ -11,6 +11,7 @@
|
|||||||
* 【core 】 EnumUtil.getBy增加带默认值重载(issue#I5RZU6@Gitee)
|
* 【core 】 EnumUtil.getBy增加带默认值重载(issue#I5RZU6@Gitee)
|
||||||
* 【core 】 ModifierUtil和ReflectUtil增加removeFinalModify(pr#810@Gitee)
|
* 【core 】 ModifierUtil和ReflectUtil增加removeFinalModify(pr#810@Gitee)
|
||||||
* 【core 】 AbsCollValueMap添加removeValue和removeValues方法,用于list value值移除(pr#813@Gitee)
|
* 【core 】 AbsCollValueMap添加removeValue和removeValues方法,用于list value值移除(pr#813@Gitee)
|
||||||
|
* 【extra 】 hutool-extra ftp 支持上传文件或目录(pr#821@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复FileNameUtil.cleanInvalid无法去除换行符问题(issue#I5RMZV@Gitee)
|
* 【core 】 修复FileNameUtil.cleanInvalid无法去除换行符问题(issue#I5RMZV@Gitee)
|
||||||
|
@ -590,38 +590,6 @@ public class Ftp extends AbstractFtp {
|
|||||||
recursiveUpload(destPath, uploadFile);
|
recursiveUpload(destPath, uploadFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 递归上传文件(支持目录)
|
|
||||||
*
|
|
||||||
* @param destPath 目录路径
|
|
||||||
* @param uploadFile 上传文件或目录
|
|
||||||
*/
|
|
||||||
public void recursiveUpload(String destPath, final File uploadFile) {
|
|
||||||
if (uploadFile.isFile()) {
|
|
||||||
this.upload(destPath, uploadFile);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File[] files = uploadFile.listFiles();
|
|
||||||
if (Objects.isNull(files)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//第一次只处理文件,防止目录在前面导致先处理子孙目录,而引发文件所在目录不正确
|
|
||||||
for (File f : files) {
|
|
||||||
if (f.isFile()) {
|
|
||||||
this.upload(destPath, f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//第二次只处理目录
|
|
||||||
for (File f : files) {
|
|
||||||
if (f.isDirectory()) {
|
|
||||||
destPath = destPath + File.separator + f.getName();
|
|
||||||
this.mkDirs(destPath);
|
|
||||||
recursiveUpload(destPath, f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载文件
|
* 下载文件
|
||||||
*
|
*
|
||||||
@ -752,4 +720,36 @@ public class Ftp extends AbstractFtp {
|
|||||||
this.client = null;
|
this.client = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归上传文件(支持目录)
|
||||||
|
*
|
||||||
|
* @param destPath 目录路径
|
||||||
|
* @param uploadFile 上传文件或目录
|
||||||
|
*/
|
||||||
|
private void recursiveUpload(String destPath, final File uploadFile) {
|
||||||
|
if (uploadFile.isFile()) {
|
||||||
|
this.upload(destPath, uploadFile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final File[] files = uploadFile.listFiles();
|
||||||
|
if (Objects.isNull(files)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//第一次只处理文件,防止目录在前面导致先处理子孙目录,而引发文件所在目录不正确
|
||||||
|
for (final File f : files) {
|
||||||
|
if (f.isFile()) {
|
||||||
|
this.upload(destPath, f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//第二次只处理目录
|
||||||
|
for (final File f : files) {
|
||||||
|
if (f.isDirectory()) {
|
||||||
|
destPath = destPath + "/" + f.getName();
|
||||||
|
this.mkDirs(destPath);
|
||||||
|
recursiveUpload(destPath, f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,10 +119,10 @@ public class SimpleFtpServer {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public SimpleFtpServer addAnonymous(String homePath) {
|
public SimpleFtpServer addAnonymous(String homePath) {
|
||||||
BaseUser user = new BaseUser();
|
final BaseUser user = new BaseUser();
|
||||||
user.setName("anonymous");
|
user.setName("anonymous");
|
||||||
user.setHomeDirectory(homePath);
|
user.setHomeDirectory(homePath);
|
||||||
List<Authority> authorities = new ArrayList<>();
|
final List<Authority> authorities = new ArrayList<>();
|
||||||
// 添加用户读写权限
|
// 添加用户读写权限
|
||||||
authorities.add(new WritePermission());
|
authorities.add(new WritePermission());
|
||||||
user.setAuthorities(authorities);
|
user.setAuthorities(authorities);
|
||||||
@ -164,7 +164,7 @@ public class SimpleFtpServer {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public SimpleFtpServer setSsl(File keystoreFile, String password) {
|
public SimpleFtpServer setSsl(File keystoreFile, String password) {
|
||||||
SslConfigurationFactory sslFactory = new SslConfigurationFactory();
|
final SslConfigurationFactory sslFactory = new SslConfigurationFactory();
|
||||||
sslFactory.setKeystoreFile(keystoreFile);
|
sslFactory.setKeystoreFile(keystoreFile);
|
||||||
sslFactory.setKeystorePassword(password);
|
sslFactory.setKeystorePassword(password);
|
||||||
return setSsl(sslFactory.createSslConfiguration());
|
return setSsl(sslFactory.createSslConfiguration());
|
||||||
|
Loading…
Reference in New Issue
Block a user