Skip to main content
Glama

ssh_download_file

Download files from a remote server via SSH to your local machine by specifying remote and local paths.

Instructions

Download a file from the remote server

Input Schema

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

Implementation Reference

  • The handler function that executes the ssh_download_file tool logic using SFTP to download files from remote server.
    private async handleSSHDownload(params: any) { const { connectionId, remotePath, localPath } = 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()); // Ensure the directory exists const dir = path.dirname(expandedLocalPath); if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: 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); } }); }); // Download the file await new Promise((resolve, reject) => { sftp.fastGet(remotePath, expandedLocalPath, (err: Error | undefined) => { if (err) { reject(new Error(`Failed to download file: ${err.message}`)); } else { resolve(true); } }); }); return { content: [{ type: "text", text: `Successfully downloaded ${remotePath} to ${expandedLocalPath}` }] }; } catch (error: any) { return { content: [{ type: "text", text: `File download failed: ${error.message}` }], isError: true }; }
  • Primary input schema definition for ssh_download_file in server capabilities registration.
    ssh_download_file: { description: "Download a file from the remote server", inputSchema: { type: "object", properties: { connectionId: { type: "string", description: "ID of an active SSH connection" }, remotePath: { type: "string", description: "Path to the file on the remote server" }, localPath: { type: "string", description: "Path where the file should be saved locally" } }, required: ["connectionId", "remotePath", "localPath"] } },
  • src/index.ts:282-283 (registration)
    Registration of the ssh_download_file handler in the main tool dispatcher switch statement.
    case 'ssh_download_file': return this.handleSSHDownload(request.params.arguments);
  • Input schema for ssh_download_file in the ListTools response.
    { name: 'ssh_download_file', description: 'Download a file from the remote server', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'ID of an active SSH connection' }, remotePath: { type: 'string', description: 'Path to the file on the remote server' }, localPath: { type: 'string', description: 'Path where the file should be saved locally' } }, required: ['connectionId', 'remotePath', 'localPath'] }
  • Input schema for ssh_download_file included in the overridden ListTools response from Ubuntu tools module.
    name: 'ssh_download_file', description: 'Download a file from the remote server', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'ID of an active SSH connection' }, remotePath: { type: 'string', description: 'Path to the file on the remote server' }, localPath: { type: 'string', description: 'Path where the file should be saved locally' } }, required: ['connectionId', 'remotePath', 'localPath'] } },

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