add upload/download function

This commit is contained in:
backuppc
2026-01-20 14:42:44 +09:00
parent 4376babbcc
commit 237ed6ea8b
3 changed files with 197 additions and 3 deletions

View File

@@ -236,6 +236,82 @@ function startServer() {
ws.send(JSON.stringify({ type: 'error', message: `삭제 실패: ${err.message}` }));
}
break;
case 'DOWNLOAD':
if (client.closed) {
ws.send(JSON.stringify({ type: 'error', message: 'FTP 연결이 끊어져 있습니다.' }));
return;
}
try {
const { remotePath, localPath, transferId } = data;
// Progress Handler
client.trackProgress(info => {
ws.send(JSON.stringify({
type: 'transfer_progress',
id: transferId,
bytes: info.bytes,
bytesOverall: info.bytesOverall,
name: info.name
}));
});
await client.downloadTo(localPath, remotePath);
client.trackProgress(); // Stop tracking
ws.send(JSON.stringify({
type: 'transfer_success',
id: transferId,
message: '다운로드 완료',
path: localPath
}));
} catch (err) {
client.trackProgress(); // Stop tracking
ws.send(JSON.stringify({
type: 'transfer_error',
id: data.transferId,
message: `다운로드 실패: ${err.message}`
}));
}
break;
case 'UPLOAD':
if (client.closed) {
ws.send(JSON.stringify({ type: 'error', message: 'FTP 연결이 끊어져 있습니다.' }));
return;
}
try {
const { remotePath, localPath, transferId } = data;
// Progress Handler
client.trackProgress(info => {
ws.send(JSON.stringify({
type: 'transfer_progress',
id: transferId,
bytes: info.bytes,
bytesOverall: info.bytesOverall,
name: info.name
}));
});
await client.uploadFrom(localPath, remotePath);
client.trackProgress();
ws.send(JSON.stringify({
type: 'transfer_success',
id: transferId,
message: '업로드 완료',
path: remotePath
}));
} catch (err) {
client.trackProgress();
ws.send(JSON.stringify({
type: 'transfer_error',
id: data.transferId,
message: `업로드 실패: ${err.message}`
}));
}
break;
}
} catch (err) {
console.error("오류 발생:", err);