资源库:SFTP上传下载删除功能优化,根据yml中配置uploadType来实现本地还是sftp上传

This commit is contained in:
曹磊 2024-05-21 09:31:50 +08:00
parent 61a8fc5198
commit f7b644ecae
1 changed files with 2 additions and 3 deletions

View File

@ -166,7 +166,7 @@ public class SFTPUtil {
try{
sftp = connect(sftpConfig);
try {
directory = getDirectory(sftpConfig.getUploadpath(), directory);
// directory = getDirectory(sftpConfig.getUploadpath(), directory);
sftp.cd(directory);
} catch (SftpException e1) {
try {
@ -386,14 +386,13 @@ public class SFTPUtil {
map.put("msg", "ftp创建" + directory + "文件路径失败");
}
}
Session session = null;
Channel channel = null;
try {
String oldfullpath = sftpConfig.getFullpath().concat(oldpath);
String newpath = directory.concat(newname);
String newfullpath = sftpConfig.getFullpath().concat(newpath);
String moveCommand = "mv " + oldfullpath + " " + newfullpath; // 移动文件的命令
session = sftp.getSession();
Session session = sftp.getSession();
channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(moveCommand);
channel.setInputStream(null);