Skip to main content
Glama
alxspiker

MCP Server for FTP Access

download-file

Retrieve files from an FTP server by specifying the remote file path. Enables direct access to server-stored files with simple, structured input.

Instructions

Download a file from the FTP server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
remotePathYesPath of the file on the FTP server

Implementation Reference

  • src/index.ts:66-96 (registration)
    Registration of the 'download-file' MCP tool, including name, description, input schema (remotePath: string), and inline handler that calls ftpClient.downloadFile and returns formatted content or error.
    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)}` } ] }; } } );
  • Inline handler function for download-file tool: orchestrates the download via ftpClient and formats MCP response.
    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)}` } ] }; } } );
  • Input schema definition for download-file tool using Zod: requires remotePath as string.
    { remotePath: z.string().describe("Path of the file on the FTP server"), },
  • Core implementation of file download in FtpClient class: connects to FTP, downloads to temp file using basic-ftp, reads content as UTF-8 string, 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)}`); } }

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