Skip to main content
Glama
alxspiker

MCP Server for FTP Access

download-file

Retrieve files from FTP servers by specifying the remote file path. This tool enables downloading documents, media, or data stored on FTP servers for local access and use.

Instructions

Download a file from the FTP server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
remotePathYesPath of the file on the FTP server

Implementation Reference

  • The inline handler function for the 'download-file' tool. It calls ftpClient.downloadFile(remotePath), extracts the content, and returns it as a text response or an error message.
    async ({ remotePath }) => { try { const { content } = await ftpClient.downloadFile(remotePath); return { content: [ { type: "text", text: `File content of ${remotePath}:\n\n${content}` } ] }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error downloading file: ${error instanceof Error ? error.message : String(error)}` } ] }; } }
  • Zod input schema defining the 'remotePath' parameter as a string.
    { remotePath: z.string().describe("Path of the file on the FTP server"), },
  • src/index.ts:65-96 (registration)
    Registers the 'download-file' tool with the MCP server, providing name, description, schema, and handler.
    // Register download-file tool server.tool( "download-file", "Download a file from the FTP server", { remotePath: z.string().describe("Path of the file on the FTP server"), }, async ({ remotePath }) => { try { const { content } = await ftpClient.downloadFile(remotePath); return { content: [ { type: "text", text: `File content of ${remotePath}:\n\n${content}` } ] }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error downloading file: ${error instanceof Error ? error.message : String(error)}` } ] }; } } );
  • FtpClient.downloadFile method: connects to FTP, downloads file to temp location using basic-ftp, reads content as UTF-8 string, disconnects, returns path and content.
    async downloadFile(remotePath: string): Promise<{filePath: string, content: string}> { try { await this.connect(); // Create a unique local filename const tempFilePath = path.join(this.tempDir, `download-${Date.now()}-${path.basename(remotePath)}`); // Download the file await this.client.downloadTo(tempFilePath, remotePath); // Read the file content const content = fs.readFileSync(tempFilePath, 'utf8'); await this.disconnect(); return { filePath: tempFilePath, content }; } catch (error) { console.error("Download file error:", error); throw new Error(`Failed to download file: ${error instanceof Error ? error.message : String(error)}`); } }

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