Skip to main content
Glama

ssh_upload_file

Transfer a file from your local system to a remote server using an active SSH connection. Specify the local file path and the desired remote destination for secure file uploads.

Instructions

Upload a file to the remote server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesID of an active SSH connection
localPathYesPath to the local file
remotePathYesPath where the file should be saved on the remote server

Implementation Reference

  • The handleSSHUpload method implements the core logic for uploading a local file to a remote server via an active SSH connection using SFTP.
    private async handleSSHUpload(params: any) { const { connectionId, localPath, remotePath } = params; // Check if the connection exists if (!this.connections.has(connectionId)) { return { content: [{ type: "text", text: `No active SSH connection with ID: ${connectionId}` }], isError: true }; } const { conn } = this.connections.get(connectionId)!; try { // Expand tilde if present in the local path const expandedLocalPath = localPath.replace(/^~/, os.homedir()); // Check if the local file exists if (!fs.existsSync(expandedLocalPath)) { return { content: [{ type: "text", text: `Local file does not exist: ${expandedLocalPath}` }], isError: true }; } // Get SFTP client const sftp: any = await new Promise((resolve, reject) => { conn.sftp((err: Error | undefined, sftp: any) => { if (err) { reject(new Error(`Failed to initialize SFTP: ${err.message}`)); } else { resolve(sftp); } }); }); // Upload the file await new Promise((resolve, reject) => { sftp.fastPut(expandedLocalPath, remotePath, (err: Error | undefined) => { if (err) { reject(new Error(`Failed to upload file: ${err.message}`)); } else { resolve(true); } }); }); return { content: [{ type: "text", text: `Successfully uploaded ${expandedLocalPath} to ${remotePath}` }] }; } catch (error: any) { return { content: [{ type: "text", text: `File upload failed: ${error.message}` }], isError: true }; } }
  • Input schema definition for the ssh_upload_file tool in server capabilities, declaring parameters, descriptions, and requirements.
    ssh_upload_file: { description: "Upload a file to the remote server", inputSchema: { type: "object", properties: { connectionId: { type: "string", description: "ID of an active SSH connection" }, localPath: { type: "string", description: "Path to the local file" }, remotePath: { type: "string", description: "Path where the file should be saved on the remote server" } }, required: ["connectionId", "localPath", "remotePath"] } },
  • src/index.ts:274-291 (registration)
    Dispatch logic in the CallToolRequestSchema handler that registers and routes calls to the ssh_upload_file handler.
    if (toolName.startsWith('ssh_')) { switch (toolName) { case 'ssh_connect': return this.handleSSHConnect(request.params.arguments); case 'ssh_exec': return this.handleSSHExec(request.params.arguments); case 'ssh_upload_file': return this.handleSSHUpload(request.params.arguments); case 'ssh_download_file': return this.handleSSHDownload(request.params.arguments); case 'ssh_list_files': return this.handleSSHListFiles(request.params.arguments); case 'ssh_disconnect': return this.handleSSHDisconnect(request.params.arguments); default: throw new Error(`Unknown SSH tool: ${toolName}`); } }

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/mixelpixx/SSH-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server