diff --git a/src/main/java/com/sftp/manager/controller/FileController.java b/src/main/java/com/sftp/manager/controller/FileController.java
index e15802c..e910e34 100644
--- a/src/main/java/com/sftp/manager/controller/FileController.java
+++ b/src/main/java/com/sftp/manager/controller/FileController.java
@@ -201,10 +201,10 @@ public class FileController {
// 本地到本地
Files.copy(new File(sourcePath).toPath(), new File(finalTargetPath).toPath());
} else if ("local".equals(sourceSessionId)) {
- // 本地到SFTP
+ // 本地到SFTP(上传到服务器)
localFileService.uploadToSftp(sourcePath, targetSessionId, finalTargetPath, sftpService);
} else if ("local".equals(targetSessionId)) {
- // SFTP到本地
+ // SFTP到本地(从服务器下载)
localFileService.downloadFromSftp(sourceSessionId, sourcePath, finalTargetPath, sftpService);
} else {
// SFTP到SFTP
@@ -214,7 +214,20 @@ public class FileController {
return ApiResponse.success("传输成功", null);
} catch (Exception e) {
- return ApiResponse.error("传输失败: " + e.getMessage());
+ String msg = e.getMessage() != null ? e.getMessage() : "未知错误";
+ String src = request.getSourceSessionId();
+ String tgt = request.getTargetSessionId();
+ String prefix;
+ if ("local".equals(src) && !"local".equals(tgt)) {
+ prefix = "上传到服务器失败";
+ } else if (!"local".equals(src) && "local".equals(tgt)) {
+ prefix = "下载到本地失败";
+ } else if (!"local".equals(src) && !"local".equals(tgt)) {
+ prefix = "服务器间传输失败";
+ } else {
+ prefix = "传输失败";
+ }
+ return ApiResponse.error(prefix + ": " + msg);
}
}
diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html
index 80467c0..51bb5d8 100644
--- a/src/main/resources/static/index.html
+++ b/src/main/resources/static/index.html
@@ -24,7 +24,8 @@
-
+
+
diff --git a/src/main/resources/static/js/app.js b/src/main/resources/static/js/app.js
index c0d1992..cea754b 100644
--- a/src/main/resources/static/js/app.js
+++ b/src/main/resources/static/js/app.js
@@ -354,7 +354,7 @@ function handleFileDrop(data, targetPanelId) {
const targetPath = panelState[targetPanelId].currentPath;
if (sourcePanelId === targetPanelId) {
- updateStatus('同面板内移动功能开发中,请使用「传输到右侧」按钮');
+ updateStatus('同面板内移动功能开发中,请使用「传输到右侧」或「传输到左侧」按钮');
return;
}
@@ -1061,19 +1061,15 @@ function downloadFiles() {
});
}
-// 传输到对面面板
-function transferFiles() {
- const sourcePanelId = getSourcePanelId();
- const targetPanelId = sourcePanelId === 'left' ? 'right' : 'left';
-
+// 按方向执行跨面板传输(源面板 -> 目标面板)
+function doTransfer(sourcePanelId, targetPanelId) {
const sourceSessionId = panelState[sourcePanelId].sessionId;
const targetSessionId = panelState[targetPanelId].sessionId;
const targetPath = panelState[targetPanelId].currentPath;
-
const selectedFiles = panelState[sourcePanelId].selectedFiles;
if (selectedFiles.length === 0) {
- alert('请先选择要传输的文件');
+ alert('请在' + (sourcePanelId === 'left' ? '左侧' : '右侧') + '面板选择要传输的文件');
return;
}
@@ -1089,7 +1085,7 @@ function transferFiles() {
showTransferCountProgress(0, total, '');
updateTransferProgress(0, '传输中 (0/' + total + ')');
- selectedFiles.forEach(function(sourcePath, index) {
+ selectedFiles.forEach(function(sourcePath) {
$.ajax({
url: API_BASE + 'api/files/transfer',
method: 'POST',
@@ -1139,6 +1135,16 @@ function transferFiles() {
updateStatus('正在传输 ' + total + ' 个文件...');
}
+// 传输到右侧:左侧面板选中的文件 -> 右侧面板
+function transferToRight() {
+ doTransfer('left', 'right');
+}
+
+// 传输到左侧:右侧面板选中的文件 -> 左侧面板
+function transferToLeft() {
+ doTransfer('right', 'left');
+}
+
// ========== 文件删除功能(模块06)==========
// 工具栏删除:删除当前活动面板中选中的文件
diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html
index 9f15f84..13206b9 100644
--- a/src/main/resources/templates/index.html
+++ b/src/main/resources/templates/index.html
@@ -24,7 +24,8 @@
-
+
+