Skip to main content
Glama
d3v1an
by d3v1an

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
NameRequiredDescriptionDefault
pathYesRuta del archivo en el servidor remoto
contentYesContenido a escribir en el archivo

Implementation Reference

  • 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",
  • 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);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/d3v1an/ssh-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server