ssh_upload
Upload a local file to a remote server using SFTP for secure file transfer and remote administration.
Instructions
Sube un archivo local al servidor remoto via SFTP
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| localPath | Yes | Ruta del archivo local a subir | |
| remotePath | Yes | Ruta destino en el servidor remoto |
Implementation Reference
- src/index.ts:246-300 (handler)The handler for `ssh_upload` which uses `sftp.fastPut` to upload files, handles rollback info creation, and updates audit logs.
private async handleUpload(args: any): Promise<CallToolResult> { this.requireConnection(); const { localPath, remotePath } = args as { localPath: string; remotePath: string }; // Capturar estado previo antes de subir let previousContent: string | undefined; let previousExisted = true; try { previousContent = await this.execCommand(`cat ${escapeShellArg(remotePath)}`); } catch { previousExisted = false; } const sftp = await this.getSftp(); return new Promise<CallToolResult>((resolve, reject) => { sftp.fastPut(localPath, remotePath, (err) => { if (err) { this.audit("ssh_upload", `${localPath} -> ${remotePath}`, "error"); reject(new Error(`Error subiendo archivo: ${err.message}`)); } else { this.audit("ssh_upload", `${localPath} -> ${remotePath}`, "ok"); const reverseInfo: ReverseInfo = previousExisted ? { type: "file_restore", description: `Restaurar contenido previo de ${remotePath}`, remotePath, previousContent, previousExisted: true, } : { type: "file_delete", description: `Eliminar ${remotePath} (no existía antes)`, remotePath, previousExisted: false, }; this.recordOperation( "ssh_upload", { localPath, remotePath }, `Archivo subido: ${localPath} -> ${remotePath}`, true, reverseInfo ); resolve({ content: [ { type: "text", text: `Archivo subido: ${localPath} -> ${remotePath}` }, ], }); } }); }); } - src/tools.ts:63-79 (schema)The schema definition for the `ssh_upload` tool.
name: "ssh_upload", description: "Sube un archivo local al servidor remoto via SFTP", inputSchema: { type: "object", properties: { localPath: { type: "string", description: "Ruta del archivo local a subir", }, remotePath: { type: "string", description: "Ruta destino en el servidor remoto", }, }, required: ["localPath", "remotePath"], }, }, - src/index.ts:67-68 (registration)Registration of the `ssh_upload` tool handler in the main request handler switch case.
case "ssh_upload": return await this.handleUpload(args);