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
| Name | Required | Description | Default |
|---|---|---|---|
| remotePath | Yes | Path 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)}` } ] }; } } );
- src/index.ts:72-96 (handler)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)}` } ] }; } } );
- src/index.ts:69-71 (schema)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"), },
- src/ftp-client.ts:72-95 (helper)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)}`); } }