ssh_upload
Upload a local file to a remote host via SFTP.
Instructions
Upload a local file to a remote host via SFTP.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host | Yes | SSH hostname or IP address | |
| port | No | SSH port (default: 22) | |
| username | No | SSH username (default: current user) | |
| privateKeyPath | No | Path to SSH private key | |
| password | No | SSH password. STRONGLY prefer key-based auth (privateKeyPath or ssh-agent). Passwords pass through MCP protocol frames as plaintext and may be logged by the transport or host process. | |
| localPath | Yes | Path to the local file to upload | |
| remotePath | Yes | Absolute path on the remote host |
Implementation Reference
- src/ssh.ts:457-469 (handler)Core handler that performs the actual SFTP file upload using ssh2's fastPut
export async function uploadFile(client: Client, localPath: string, remotePath: string): Promise<void> { const sftp = await getSftp(client); try { await new Promise<void>((resolve, reject) => { sftp.fastPut(localPath, remotePath, (err) => { if (err) return reject(err); resolve(); }); }); } finally { sftp.end(); } } - src/tools.ts:90-104 (registration)Registers the 'ssh_upload' tool with MCP server, defining schema and handler logic
server.tool( "ssh_upload", "Upload a local file to a remote host via SFTP.", { ...connectionParams, localPath: z.string().describe("Path to the local file to upload"), remotePath: z.string().describe("Absolute path on the remote host"), }, async ({ localPath, remotePath, ...conn }) => { return connectionPool.withConnection(conn, async (client) => { await uploadFile(client, localPath, remotePath); return { content: [{ type: "text", text: `Uploaded ${localPath} → ${remotePath}` }] }; }); }, ); - src/tools.ts:93-97 (schema)Input schema for ssh_upload: connection params (host, port, username, privateKeyPath, password) plus localPath and remotePath
{ ...connectionParams, localPath: z.string().describe("Path to the local file to upload"), remotePath: z.string().describe("Absolute path on the remote host"), }, - src/ssh.ts:407-414 (helper)Helper that obtains an SFTP session from the SSH client connection
function getSftp(client: Client): Promise<SFTPWrapper> { return new Promise((resolve, reject) => { client.sftp((err, sftp) => { if (err) return reject(err); resolve(sftp); }); }); } - src/server.ts:53-62 (registration)Re-exports uploadFile and registerTools from src/server.ts
downloadFile, exec, formatDiagnostics, listDir, readFile, readKnownHostsKeys, resolveConfig, uploadFile, writeFile, } from "./ssh.js";