Skip to main content
Glama

ssh_download_file

Download files from a remote server via SSH by specifying the connection ID, remote file path, and local save location.

Instructions

Download a file from the remote server

Input Schema

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

Implementation Reference

  • The main handler function that downloads a file from the remote SSH server to local using SFTP.
    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 }; }
  • Input schema definition for the ssh_download_file tool in server capabilities.
    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 in the ListTools response handler.
    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'] }
  • src/index.ts:282-283 (registration)
    Registration of the ssh_download_file handler in the tool call switch statement.
    case 'ssh_download_file': return this.handleSSHDownload(request.params.arguments);

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