ssh_write_file
Write content to a file on a remote SSH server. Use this tool to create or modify files through secure SSH connections for remote administration tasks.
Instructions
Escribe contenido a un archivo en el servidor remoto
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Ruta del archivo en el servidor remoto | |
| content | Yes | Contenido a escribir en el archivo |
Implementation Reference
- src/index.ts:382-412 (handler)The handleWriteFile method performs the actual writing operation to a remote file via SFTP. It also handles capturing the previous state for undo/audit purposes.
private async handleWriteFile(args: any): Promise<CallToolResult> { this.requireConnection(); const { path: remotePath, content } = args as { path: string; content: string }; // Capturar estado previo antes de escribir 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) => { const stream = sftp.createWriteStream(remotePath); stream.on("close", () => { this.audit("ssh_write_file", remotePath, "ok"); const reverseInfo: ReverseInfo = previousExisted ? { type: "file_restore", description: `Restaurar contenido previo de ${remotePath}`, remotePath, previousContent, previousExisted: true, } : { type: "file_delete", - src/tools.ts:125-140 (schema)Input schema definition for the ssh_write_file tool.
{ name: "ssh_write_file", description: "Escribe contenido a un archivo en el servidor remoto", inputSchema: { type: "object", properties: { path: { type: "string", description: "Ruta del archivo en el servidor remoto", }, content: { type: "string", description: "Contenido a escribir en el archivo", }, }, required: ["path", "content"], - src/index.ts:75-76 (registration)Tool execution dispatch in the main loop.
case "ssh_write_file": return await this.handleWriteFile(args);