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
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Content to upload to the file | |
| remotePath | Yes | Destination path on the FTP server |
Implementation Reference
- src/index.ts:106-129 (handler)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)}` } ] }; } }
- src/index.ts:102-105 (schema)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)}` } ] }; } } );
- src/ftp-client.ts:97-117 (helper)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)}`); } }