Skip to main content
Glama
alxspiker

MCP Server for FTP Access

upload-file

Upload files to an FTP server by specifying the destination path and content. This tool enables users to transfer data directly to remote servers through natural language commands.

Instructions

Upload a file to the FTP server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesContent to upload to the file
remotePathYesDestination path on the FTP server

Implementation Reference

  • MCP tool handler for 'upload-file': wraps ftpClient.uploadFile with error handling and standardized MCP response format.
    async ({ remotePath, content }) => { try { await ftpClient.uploadFile(remotePath, content); return { content: [ { type: "text", text: `File successfully uploaded to ${remotePath}` } ] }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error uploading file: ${error instanceof Error ? error.message : String(error)}` } ] }; } }
  • Zod input schema defining parameters for the upload-file tool: remotePath and content.
    { remotePath: z.string().describe("Destination path on the FTP server"), content: z.string().describe("Content to upload to the file"), },
  • src/index.ts:99-130 (registration)
    Registration of the 'upload-file' tool on the MCP server using server.tool, including name, description, schema, and handler.
    server.tool( "upload-file", "Upload a file to the FTP server", { remotePath: z.string().describe("Destination path on the FTP server"), content: z.string().describe("Content to upload to the file"), }, async ({ remotePath, content }) => { try { await ftpClient.uploadFile(remotePath, content); return { content: [ { type: "text", text: `File successfully uploaded to ${remotePath}` } ] }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error uploading file: ${error instanceof Error ? error.message : String(error)}` } ] }; } } );
  • FtpClient.uploadFile method: implements the core FTP upload logic by writing content to temp file and using basic-ftp client to upload.
    async uploadFile(remotePath: string, content: string): Promise<boolean> { try { await this.connect(); // Create a temporary file with the content const tempFilePath = path.join(this.tempDir, `upload-${Date.now()}-${path.basename(remotePath)}`); fs.writeFileSync(tempFilePath, content); // Upload the file await this.client.uploadFrom(tempFilePath, remotePath); // Clean up fs.unlinkSync(tempFilePath); await this.disconnect(); return true; } catch (error) { console.error("Upload file error:", error); throw new Error(`Failed to upload file: ${error instanceof Error ? error.message : String(error)}`); } }

Other Tools

Related Tools

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/alxspiker/mcp-server-ftp'

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