ssh_upload
Upload files from local system to remote SSH server using MCP SSH Manager. Specify server name, local file path, and remote destination path for secure file transfer.
Instructions
Upload file to remote SSH server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| server | Yes | Server name | |
| localPath | Yes | Local file path | |
| remotePath | Yes | Remote destination path |
Implementation Reference
- src/tool-registry.js:13-20 (registration)Registration of the 'ssh_upload' tool as part of the essential core SSH operations group in the centralized tool registry.// Core group (5 tools) - Essential SSH operations core: [ 'ssh_list_servers', 'ssh_execute', 'ssh_upload', 'ssh_download', 'ssh_sync' ],
- src/ssh-manager.js:346-381 (handler)The putFile method in SSHManager class provides the core implementation for uploading files to remote servers. It handles path resolution for '~' (expands to user's home directory), initializes SFTP if needed, checks local file existence, and uses ssh2's fastPut for efficient transfer.async putFile(localPath, remotePath) { // SFTP doesn't resolve ~ automatically, we need to get the real path let resolvedRemotePath = remotePath; if (remotePath.includes('~')) { try { const homeDir = await this.resolveHomePath(); // Replace ~ with the actual home directory // Handle both ~/path and ~ alone if (remotePath === '~') { resolvedRemotePath = homeDir; } else if (remotePath.startsWith('~/')) { resolvedRemotePath = homeDir + remotePath.substring(1); } else { // If ~ is not at the beginning, don't replace it resolvedRemotePath = remotePath; } } catch (err) { // If we can't resolve home, throw a more descriptive error throw new Error(`Failed to resolve home directory for path: ${remotePath}. ${err.message}`); } } const sftp = await this.getSFTP(); return new Promise((resolve, reject) => { // Check if local file exists and is readable if (!fs.existsSync(localPath)) { reject(new Error(`Local file does not exist: ${localPath}`)); return; } sftp.fastPut(localPath, resolvedRemotePath, (err) => { if (err) reject(err); else resolve(); }); }); }
- src/ssh-manager.js:414-429 (helper)putFiles helper method for batch uploading multiple files, calling putFile for each and collecting results with optional stop-on-error.async putFiles(files, options = {}) { const sftp = await this.getSFTP(); const results = []; for (const file of files) { try { await this.putFile(file.local, file.remote); results.push({ ...file, success: true }); } catch (error) { results.push({ ...file, success: false, error: error.message }); if (options.stopOnError) break; } } return results; }