Skip to main content
Glama
alxspiker

MCP Server for FTP Access

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
NameRequiredDescriptionDefault
remotePathYesDestination path on the FTP server
contentYesContent 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)}`
              }
            ]
          };
        }
      }
    );
  • 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"),
    },
  • 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)}`
            }
          ]
        };
      }
    }
  • 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)}`);
      }
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other 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