mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
hutool-extra ftp 支持上传文件或目录
This commit is contained in:
@@ -590,38 +590,6 @@ public class Ftp extends AbstractFtp {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归上传文件(支持目录)
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public SimpleFtpServer addAnonymous(String homePath) {
|
||||
BaseUser user = new BaseUser();
|
||||
final BaseUser user = new BaseUser();
|
||||
user.setName("anonymous");
|
||||
user.setHomeDirectory(homePath);
|
||||
List<Authority> authorities = new ArrayList<>();
|
||||
final List<Authority> authorities = new ArrayList<>();
|
||||
// 添加用户读写权限
|
||||
authorities.add(new WritePermission());
|
||||
user.setAuthorities(authorities);
|
||||
@@ -164,7 +164,7 @@ public class SimpleFtpServer {
|
||||
* @return this
|
||||
*/
|
||||
public SimpleFtpServer setSsl(File keystoreFile, String password) {
|
||||
SslConfigurationFactory sslFactory = new SslConfigurationFactory();
|
||||
final SslConfigurationFactory sslFactory = new SslConfigurationFactory();
|
||||
sslFactory.setKeystoreFile(keystoreFile);
|
||||
sslFactory.setKeystorePassword(password);
|
||||
return setSsl(sslFactory.createSslConfiguration());
|
||||
|
Reference in New Issue
Block a user