mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
sftp 新增将本地文件或者文件夹同步上传到远程目录的方法
This commit is contained in:
parent
81c7bb4b46
commit
0c730e249c
@ -17,6 +17,7 @@ import com.jcraft.jsch.SftpException;
|
||||
import com.jcraft.jsch.SftpProgressMonitor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
@ -423,6 +424,35 @@ public class Sftp extends AbstractFtp {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将本地文件或者文件夹同步(覆盖)上传到远程路径
|
||||
*
|
||||
* @param file 文件或者文件夹
|
||||
* @param remotePath 远程路径
|
||||
*/
|
||||
public void syncPath(File file, String remotePath) {
|
||||
if (!FileUtil.exist(file)) {
|
||||
return;
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
if (files == null) {
|
||||
return;
|
||||
}
|
||||
for (File fileItem : files) {
|
||||
if (fileItem.isDirectory()) {
|
||||
String mkdir = FileUtil.normalize(remotePath + "/" + fileItem.getName());
|
||||
this.syncPath(fileItem, mkdir);
|
||||
} else {
|
||||
this.syncPath(fileItem, remotePath);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.mkDirs(remotePath);
|
||||
this.upload(remotePath, file);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean upload(String destPath, File file) {
|
||||
put(FileUtil.getAbsolutePath(file), destPath);
|
||||
|
Loading…
x
Reference in New Issue
Block a user