upload-file
Upload files to FTP servers by specifying destination paths and content. This tool enables transferring files to remote FTP locations through the MCP server for FTP access.
Instructions
Upload a file to the FTP server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| remotePath | Yes | Destination path on the FTP server | |
| content | Yes | Content to upload to the file |
Implementation Reference
- src/index.ts:99-130 (registration)Registration of the 'upload-file' MCP tool using server.tool(). Includes input schema (remotePath, content) and inline handler that calls ftpClient.uploadFile() and returns formatted text response.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/index.ts:102-105 (schema)Zod input schema defining parameters for the upload-file tool: remotePath (destination path) and content (file content as string).{ remotePath: z.string().describe("Destination path on the FTP server"), content: z.string().describe("Content to upload to the file"), },
- src/index.ts:106-129 (handler)Inline handler function for upload-file tool: invokes ftpClient.uploadFile with parameters and returns MCP-formatted success or error response.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)Core FTP upload logic in FtpClient class: writes content to temp file, uses basic-ftp Client.uploadFrom to upload to remotePath, handles connection and cleanup.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)}`); } }