mcp-ssh-manager 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +10 -1
- package/CLAUDE.md +16 -0
- package/README.md +62 -0
- package/cli/commands/server.sh +27 -5
- package/cli/commands/tools.sh +603 -0
- package/cli/lib/config.sh +104 -14
- package/cli/lib/menu.sh +124 -0
- package/cli/ssh-manager +17 -7
- package/docs/TOOL_MANAGEMENT.md +473 -0
- package/package.json +5 -4
- package/scripts/validate.sh +12 -0
- package/src/backup-manager.js +12 -12
- package/src/command-aliases.js +16 -16
- package/src/config-loader.js +1 -1
- package/src/database-manager.js +38 -40
- package/src/deploy-helper.js +12 -13
- package/src/health-monitor.js +26 -26
- package/src/hooks-system.js +43 -43
- package/src/index.js +866 -832
- package/src/logger.js +53 -53
- package/src/profile-loader.js +14 -14
- package/src/server-aliases.js +11 -11
- package/src/server-groups.js +98 -97
- package/src/session-manager.js +59 -58
- package/src/ssh-key-manager.js +1 -1
- package/src/ssh-manager.js +44 -23
- package/src/tool-config-manager.js +434 -0
- package/src/tool-registry.js +196 -0
- package/src/tunnel-manager.js +98 -98
package/src/session-manager.js
CHANGED
|
@@ -36,7 +36,7 @@ class SSHSession {
|
|
|
36
36
|
this.outputBuffer = '';
|
|
37
37
|
this.errorBuffer = '';
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
/**
|
|
41
41
|
* Initialize the session with a shell
|
|
42
42
|
*/
|
|
@@ -45,19 +45,19 @@ class SSHSession {
|
|
|
45
45
|
logger.info(`Initializing SSH session ${this.id}`, {
|
|
46
46
|
server: this.serverName
|
|
47
47
|
});
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
// Start an interactive shell
|
|
50
50
|
this.shell = await this.ssh.requestShell({
|
|
51
51
|
term: 'xterm-256color',
|
|
52
52
|
cols: 80,
|
|
53
53
|
rows: 24
|
|
54
54
|
});
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
// Setup event handlers
|
|
57
57
|
this.shell.on('data', (data) => {
|
|
58
58
|
this.outputBuffer += data.toString();
|
|
59
59
|
this.lastActivity = new Date();
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
// Log output in verbose mode
|
|
62
62
|
if (logger.verbose) {
|
|
63
63
|
logger.debug(`Session ${this.id} output`, {
|
|
@@ -65,33 +65,34 @@ class SSHSession {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
this.shell.on('close', () => {
|
|
70
70
|
logger.info(`Session ${this.id} shell closed`);
|
|
71
71
|
this.state = SESSION_STATES.CLOSED;
|
|
72
72
|
this.cleanup();
|
|
73
73
|
});
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
this.shell.stderr.on('data', (data) => {
|
|
76
76
|
this.errorBuffer += data.toString();
|
|
77
77
|
logger.warn(`Session ${this.id} stderr`, {
|
|
78
78
|
error: data.toString()
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
// Wait for shell prompt
|
|
83
83
|
await this.waitForPrompt();
|
|
84
|
-
|
|
84
|
+
|
|
85
|
+
// Allow context queries through standard execute flow
|
|
86
|
+
this.state = SESSION_STATES.READY;
|
|
87
|
+
|
|
85
88
|
// Get initial working directory
|
|
86
89
|
await this.updateContext();
|
|
87
|
-
|
|
88
|
-
this.state = SESSION_STATES.READY;
|
|
89
|
-
|
|
90
|
+
|
|
90
91
|
logger.info(`Session ${this.id} initialized`, {
|
|
91
92
|
server: this.serverName,
|
|
92
93
|
cwd: this.context.cwd
|
|
93
94
|
});
|
|
94
|
-
|
|
95
|
+
|
|
95
96
|
} catch (error) {
|
|
96
97
|
this.state = SESSION_STATES.ERROR;
|
|
97
98
|
logger.error(`Failed to initialize session ${this.id}`, {
|
|
@@ -100,26 +101,26 @@ class SSHSession {
|
|
|
100
101
|
throw error;
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
+
|
|
104
105
|
/**
|
|
105
106
|
* Wait for shell prompt
|
|
106
107
|
*/
|
|
107
108
|
async waitForPrompt(timeout = 5000) {
|
|
108
109
|
const startTime = Date.now();
|
|
109
|
-
|
|
110
|
+
|
|
110
111
|
while (Date.now() - startTime < timeout) {
|
|
111
112
|
// Check if we have a prompt (ends with $ or # typically)
|
|
112
113
|
if (this.outputBuffer.match(/[$#>]\s*$/)) {
|
|
113
114
|
return true;
|
|
114
115
|
}
|
|
115
|
-
|
|
116
|
+
|
|
116
117
|
// Wait a bit
|
|
117
118
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
118
119
|
}
|
|
119
|
-
|
|
120
|
+
|
|
120
121
|
throw new Error('Timeout waiting for shell prompt');
|
|
121
122
|
}
|
|
122
|
-
|
|
123
|
+
|
|
123
124
|
/**
|
|
124
125
|
* Update session context (pwd, env)
|
|
125
126
|
*/
|
|
@@ -130,7 +131,7 @@ class SSHSession {
|
|
|
130
131
|
if (pwdResult.success) {
|
|
131
132
|
this.context.cwd = pwdResult.output.trim();
|
|
132
133
|
}
|
|
133
|
-
|
|
134
|
+
|
|
134
135
|
// Get environment variables (selective)
|
|
135
136
|
const envResult = await this.execute('echo $PATH:$USER:$HOME', { silent: true });
|
|
136
137
|
if (envResult.success) {
|
|
@@ -143,7 +144,7 @@ class SSHSession {
|
|
|
143
144
|
});
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
|
-
|
|
147
|
+
|
|
147
148
|
/**
|
|
148
149
|
* Execute a command in the session
|
|
149
150
|
*/
|
|
@@ -151,15 +152,15 @@ class SSHSession {
|
|
|
151
152
|
if (this.state !== SESSION_STATES.READY) {
|
|
152
153
|
throw new Error(`Session ${this.id} is not ready (state: ${this.state})`);
|
|
153
154
|
}
|
|
154
|
-
|
|
155
|
+
|
|
155
156
|
this.state = SESSION_STATES.BUSY;
|
|
156
157
|
this.lastActivity = new Date();
|
|
157
|
-
|
|
158
|
+
|
|
158
159
|
try {
|
|
159
160
|
// Clear buffers
|
|
160
161
|
this.outputBuffer = '';
|
|
161
162
|
this.errorBuffer = '';
|
|
162
|
-
|
|
163
|
+
|
|
163
164
|
// Add to history unless silent
|
|
164
165
|
if (!options.silent) {
|
|
165
166
|
this.context.history.push({
|
|
@@ -167,53 +168,53 @@ class SSHSession {
|
|
|
167
168
|
timestamp: new Date(),
|
|
168
169
|
cwd: this.context.cwd
|
|
169
170
|
});
|
|
170
|
-
|
|
171
|
+
|
|
171
172
|
logger.info(`Session ${this.id} executing`, {
|
|
172
173
|
command: command.substring(0, 100),
|
|
173
174
|
server: this.serverName
|
|
174
175
|
});
|
|
175
176
|
}
|
|
176
|
-
|
|
177
|
+
|
|
177
178
|
// Send command
|
|
178
179
|
this.shell.write(command + '\n');
|
|
179
|
-
|
|
180
|
+
|
|
180
181
|
// Wait for command to complete
|
|
181
182
|
await this.waitForPrompt(options.timeout || 30000);
|
|
182
|
-
|
|
183
|
+
|
|
183
184
|
// Parse output (remove command echo and prompt)
|
|
184
185
|
let output = this.outputBuffer;
|
|
185
|
-
|
|
186
|
+
|
|
186
187
|
// Remove the command echo (first line)
|
|
187
188
|
const lines = output.split('\n');
|
|
188
189
|
if (lines[0].includes(command)) {
|
|
189
190
|
lines.shift();
|
|
190
191
|
}
|
|
191
|
-
|
|
192
|
+
|
|
192
193
|
// Remove the prompt (last line)
|
|
193
194
|
const lastLine = lines[lines.length - 1];
|
|
194
195
|
if (lastLine.match(/[$#>]\s*$/)) {
|
|
195
196
|
lines.pop();
|
|
196
197
|
}
|
|
197
|
-
|
|
198
|
+
|
|
198
199
|
output = lines.join('\n').trim();
|
|
199
|
-
|
|
200
|
+
|
|
200
201
|
// Check for command success (basic heuristic)
|
|
201
202
|
const success = !this.errorBuffer && !output.includes('command not found');
|
|
202
|
-
|
|
203
|
+
|
|
203
204
|
// Update context if command might have changed it
|
|
204
205
|
if (command.startsWith('cd ') || command.startsWith('export ')) {
|
|
205
206
|
await this.updateContext();
|
|
206
207
|
}
|
|
207
|
-
|
|
208
|
+
|
|
208
209
|
this.state = SESSION_STATES.READY;
|
|
209
|
-
|
|
210
|
+
|
|
210
211
|
return {
|
|
211
212
|
success,
|
|
212
213
|
output,
|
|
213
214
|
error: this.errorBuffer,
|
|
214
215
|
session: this.id
|
|
215
216
|
};
|
|
216
|
-
|
|
217
|
+
|
|
217
218
|
} catch (error) {
|
|
218
219
|
this.state = SESSION_STATES.ERROR;
|
|
219
220
|
logger.error(`Session ${this.id} execution failed`, {
|
|
@@ -223,7 +224,7 @@ class SSHSession {
|
|
|
223
224
|
throw error;
|
|
224
225
|
}
|
|
225
226
|
}
|
|
226
|
-
|
|
227
|
+
|
|
227
228
|
/**
|
|
228
229
|
* Set session variable
|
|
229
230
|
*/
|
|
@@ -231,14 +232,14 @@ class SSHSession {
|
|
|
231
232
|
this.context.variables[name] = value;
|
|
232
233
|
this.lastActivity = new Date();
|
|
233
234
|
}
|
|
234
|
-
|
|
235
|
+
|
|
235
236
|
/**
|
|
236
237
|
* Get session variable
|
|
237
238
|
*/
|
|
238
239
|
getVariable(name) {
|
|
239
240
|
return this.context.variables[name];
|
|
240
241
|
}
|
|
241
|
-
|
|
242
|
+
|
|
242
243
|
/**
|
|
243
244
|
* Get session info
|
|
244
245
|
*/
|
|
@@ -255,23 +256,23 @@ class SSHSession {
|
|
|
255
256
|
variables: Object.keys(this.context.variables)
|
|
256
257
|
};
|
|
257
258
|
}
|
|
258
|
-
|
|
259
|
+
|
|
259
260
|
/**
|
|
260
261
|
* Close the session
|
|
261
262
|
*/
|
|
262
263
|
close() {
|
|
263
264
|
logger.info(`Closing session ${this.id}`);
|
|
264
|
-
|
|
265
|
+
|
|
265
266
|
if (this.shell) {
|
|
266
267
|
this.shell.write('exit\n');
|
|
267
268
|
this.shell.end();
|
|
268
269
|
this.shell = null;
|
|
269
270
|
}
|
|
270
|
-
|
|
271
|
+
|
|
271
272
|
this.state = SESSION_STATES.CLOSED;
|
|
272
273
|
this.cleanup();
|
|
273
274
|
}
|
|
274
|
-
|
|
275
|
+
|
|
275
276
|
/**
|
|
276
277
|
* Cleanup resources
|
|
277
278
|
*/
|
|
@@ -288,18 +289,18 @@ class SSHSession {
|
|
|
288
289
|
*/
|
|
289
290
|
export async function createSession(serverName, ssh) {
|
|
290
291
|
const sessionId = `ssh_${Date.now()}_${uuidv4().substring(0, 8)}`;
|
|
291
|
-
|
|
292
|
+
|
|
292
293
|
const session = new SSHSession(sessionId, serverName, ssh);
|
|
293
294
|
sessions.set(sessionId, session);
|
|
294
|
-
|
|
295
|
+
|
|
295
296
|
try {
|
|
296
297
|
await session.initialize();
|
|
297
|
-
|
|
298
|
+
|
|
298
299
|
logger.info('SSH session created', {
|
|
299
300
|
id: sessionId,
|
|
300
301
|
server: serverName
|
|
301
302
|
});
|
|
302
|
-
|
|
303
|
+
|
|
303
304
|
return session;
|
|
304
305
|
} catch (error) {
|
|
305
306
|
sessions.delete(sessionId);
|
|
@@ -312,15 +313,15 @@ export async function createSession(serverName, ssh) {
|
|
|
312
313
|
*/
|
|
313
314
|
export function getSession(sessionId) {
|
|
314
315
|
const session = sessions.get(sessionId);
|
|
315
|
-
|
|
316
|
+
|
|
316
317
|
if (!session) {
|
|
317
318
|
throw new Error(`Session ${sessionId} not found`);
|
|
318
319
|
}
|
|
319
|
-
|
|
320
|
+
|
|
320
321
|
if (session.state === SESSION_STATES.CLOSED) {
|
|
321
322
|
throw new Error(`Session ${sessionId} is closed`);
|
|
322
323
|
}
|
|
323
|
-
|
|
324
|
+
|
|
324
325
|
return session;
|
|
325
326
|
}
|
|
326
327
|
|
|
@@ -329,13 +330,13 @@ export function getSession(sessionId) {
|
|
|
329
330
|
*/
|
|
330
331
|
export function listSessions() {
|
|
331
332
|
const activeSessions = [];
|
|
332
|
-
|
|
333
|
+
|
|
333
334
|
for (const [id, session] of sessions.entries()) {
|
|
334
335
|
if (session.state !== SESSION_STATES.CLOSED) {
|
|
335
336
|
activeSessions.push(session.getInfo());
|
|
336
337
|
}
|
|
337
338
|
}
|
|
338
|
-
|
|
339
|
+
|
|
339
340
|
return activeSessions;
|
|
340
341
|
}
|
|
341
342
|
|
|
@@ -344,11 +345,11 @@ export function listSessions() {
|
|
|
344
345
|
*/
|
|
345
346
|
export function closeSession(sessionId) {
|
|
346
347
|
const session = sessions.get(sessionId);
|
|
347
|
-
|
|
348
|
+
|
|
348
349
|
if (!session) {
|
|
349
350
|
throw new Error(`Session ${sessionId} not found`);
|
|
350
351
|
}
|
|
351
|
-
|
|
352
|
+
|
|
352
353
|
session.close();
|
|
353
354
|
return true;
|
|
354
355
|
}
|
|
@@ -358,14 +359,14 @@ export function closeSession(sessionId) {
|
|
|
358
359
|
*/
|
|
359
360
|
export function closeServerSessions(serverName) {
|
|
360
361
|
let closedCount = 0;
|
|
361
|
-
|
|
362
|
+
|
|
362
363
|
for (const [id, session] of sessions.entries()) {
|
|
363
364
|
if (session.serverName === serverName) {
|
|
364
365
|
session.close();
|
|
365
366
|
closedCount++;
|
|
366
367
|
}
|
|
367
368
|
}
|
|
368
|
-
|
|
369
|
+
|
|
369
370
|
return closedCount;
|
|
370
371
|
}
|
|
371
372
|
|
|
@@ -375,10 +376,10 @@ export function closeServerSessions(serverName) {
|
|
|
375
376
|
export function cleanupSessions(maxAge = 30 * 60 * 1000) { // 30 minutes default
|
|
376
377
|
const now = Date.now();
|
|
377
378
|
let cleanedCount = 0;
|
|
378
|
-
|
|
379
|
+
|
|
379
380
|
for (const [id, session] of sessions.entries()) {
|
|
380
381
|
const age = now - session.lastActivity.getTime();
|
|
381
|
-
|
|
382
|
+
|
|
382
383
|
if (age > maxAge) {
|
|
383
384
|
logger.info(`Cleaning up inactive session ${id}`, {
|
|
384
385
|
age: Math.floor(age / 1000) + 's'
|
|
@@ -387,7 +388,7 @@ export function cleanupSessions(maxAge = 30 * 60 * 1000) { // 30 minutes default
|
|
|
387
388
|
cleanedCount++;
|
|
388
389
|
}
|
|
389
390
|
}
|
|
390
|
-
|
|
391
|
+
|
|
391
392
|
return cleanedCount;
|
|
392
393
|
}
|
|
393
394
|
|
|
@@ -407,4 +408,4 @@ export default {
|
|
|
407
408
|
closeServerSessions,
|
|
408
409
|
cleanupSessions,
|
|
409
410
|
SESSION_STATES
|
|
410
|
-
};
|
|
411
|
+
};
|
package/src/ssh-key-manager.js
CHANGED
package/src/ssh-manager.js
CHANGED
|
@@ -4,6 +4,7 @@ import { promisify } from 'util';
|
|
|
4
4
|
import crypto from 'crypto';
|
|
5
5
|
import { isHostKnown, getCurrentHostKey, addHostKey, updateHostKey } from './ssh-key-manager.js';
|
|
6
6
|
import { configLoader } from './config-loader.js';
|
|
7
|
+
import { logger } from './logger.js';
|
|
7
8
|
|
|
8
9
|
class SSHManager {
|
|
9
10
|
constructor(config) {
|
|
@@ -48,7 +49,7 @@ class SSHManager {
|
|
|
48
49
|
},
|
|
49
50
|
debug: (info) => {
|
|
50
51
|
if (info.includes('Handshake') || info.includes('error')) {
|
|
51
|
-
|
|
52
|
+
logger.debug('SSH2 Debug', { info });
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
};
|
|
@@ -63,23 +64,27 @@ class SSHManager {
|
|
|
63
64
|
if (isHostKnown(host, port)) {
|
|
64
65
|
// For now, accept all known hosts
|
|
65
66
|
// TODO: Implement proper fingerprint comparison once we understand SSH2's hash format
|
|
66
|
-
|
|
67
|
+
logger.info('Host key verified', { host, port });
|
|
67
68
|
return true;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
// Host is not known
|
|
71
|
-
|
|
72
|
+
logger.info('New host detected', { host, port });
|
|
72
73
|
|
|
73
74
|
// If autoAcceptHostKey is enabled, accept and add the key
|
|
74
75
|
if (this.autoAcceptHostKey) {
|
|
75
|
-
|
|
76
|
+
logger.info('Auto-accept host key', { host, port });
|
|
76
77
|
// Schedule key addition after connection
|
|
77
78
|
setImmediate(async () => {
|
|
78
79
|
try {
|
|
79
80
|
await addHostKey(host, port);
|
|
80
|
-
|
|
81
|
+
logger.info('Host key added', { host, port });
|
|
81
82
|
} catch (err) {
|
|
82
|
-
|
|
83
|
+
logger.warn('Failed to add host key', {
|
|
84
|
+
host,
|
|
85
|
+
port,
|
|
86
|
+
error: err.message
|
|
87
|
+
});
|
|
83
88
|
}
|
|
84
89
|
});
|
|
85
90
|
return true;
|
|
@@ -87,7 +92,7 @@ class SSHManager {
|
|
|
87
92
|
|
|
88
93
|
// For backward compatibility, accept new hosts by default
|
|
89
94
|
// In production, you might want to prompt the user or check a whitelist
|
|
90
|
-
|
|
95
|
+
logger.warn('Auto-accepting new host', { host, port });
|
|
91
96
|
return true;
|
|
92
97
|
};
|
|
93
98
|
}
|
|
@@ -125,7 +130,7 @@ class SSHManager {
|
|
|
125
130
|
timeoutId = setTimeout(() => {
|
|
126
131
|
if (!completed) {
|
|
127
132
|
completed = true;
|
|
128
|
-
|
|
133
|
+
|
|
129
134
|
// Try multiple ways to kill the stream
|
|
130
135
|
if (stream) {
|
|
131
136
|
try {
|
|
@@ -136,7 +141,7 @@ class SSHManager {
|
|
|
136
141
|
// Ignore errors
|
|
137
142
|
}
|
|
138
143
|
}
|
|
139
|
-
|
|
144
|
+
|
|
140
145
|
// Kill the entire client connection as last resort
|
|
141
146
|
try {
|
|
142
147
|
this.client.end();
|
|
@@ -144,7 +149,7 @@ class SSHManager {
|
|
|
144
149
|
} catch (e) {
|
|
145
150
|
// Ignore errors
|
|
146
151
|
}
|
|
147
|
-
|
|
152
|
+
|
|
148
153
|
reject(new Error(`Command timeout after ${timeout}ms: ${command.substring(0, 100)}...`));
|
|
149
154
|
}
|
|
150
155
|
}, timeout);
|
|
@@ -237,6 +242,22 @@ class SSHManager {
|
|
|
237
242
|
});
|
|
238
243
|
}
|
|
239
244
|
|
|
245
|
+
async requestShell(options = {}) {
|
|
246
|
+
if (!this.connected) {
|
|
247
|
+
throw new Error('Not connected to SSH server');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return new Promise((resolve, reject) => {
|
|
251
|
+
this.client.shell(options, (err, stream) => {
|
|
252
|
+
if (err) {
|
|
253
|
+
reject(err);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
resolve(stream);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
240
261
|
async getSFTP() {
|
|
241
262
|
if (this.sftp) return this.sftp;
|
|
242
263
|
|
|
@@ -258,12 +279,12 @@ class SSHManager {
|
|
|
258
279
|
}
|
|
259
280
|
|
|
260
281
|
let homeDir = null;
|
|
261
|
-
|
|
282
|
+
|
|
262
283
|
// Method 1: Try getent (most reliable)
|
|
263
284
|
try {
|
|
264
|
-
const result = await this.execCommand('getent passwd $USER | cut -d: -f6', {
|
|
265
|
-
timeout: 5000,
|
|
266
|
-
rawCommand: true
|
|
285
|
+
const result = await this.execCommand('getent passwd $USER | cut -d: -f6', {
|
|
286
|
+
timeout: 5000,
|
|
287
|
+
rawCommand: true
|
|
267
288
|
});
|
|
268
289
|
homeDir = result.stdout.trim();
|
|
269
290
|
if (homeDir && homeDir.startsWith('/')) {
|
|
@@ -306,9 +327,9 @@ class SSHManager {
|
|
|
306
327
|
|
|
307
328
|
// Method 4: Last resort - try cd ~ && pwd
|
|
308
329
|
try {
|
|
309
|
-
const result = await this.execCommand('cd ~ && pwd', {
|
|
310
|
-
timeout: 5000,
|
|
311
|
-
rawCommand: true
|
|
330
|
+
const result = await this.execCommand('cd ~ && pwd', {
|
|
331
|
+
timeout: 5000,
|
|
332
|
+
rawCommand: true
|
|
312
333
|
});
|
|
313
334
|
homeDir = result.stdout.trim();
|
|
314
335
|
if (homeDir && homeDir.startsWith('/')) {
|
|
@@ -343,7 +364,7 @@ class SSHManager {
|
|
|
343
364
|
throw new Error(`Failed to resolve home directory for path: ${remotePath}. ${err.message}`);
|
|
344
365
|
}
|
|
345
366
|
}
|
|
346
|
-
|
|
367
|
+
|
|
347
368
|
const sftp = await this.getSFTP();
|
|
348
369
|
return new Promise((resolve, reject) => {
|
|
349
370
|
// Check if local file exists and is readable
|
|
@@ -351,7 +372,7 @@ class SSHManager {
|
|
|
351
372
|
reject(new Error(`Local file does not exist: ${localPath}`));
|
|
352
373
|
return;
|
|
353
374
|
}
|
|
354
|
-
|
|
375
|
+
|
|
355
376
|
sftp.fastPut(localPath, resolvedRemotePath, (err) => {
|
|
356
377
|
if (err) reject(err);
|
|
357
378
|
else resolve();
|
|
@@ -380,7 +401,7 @@ class SSHManager {
|
|
|
380
401
|
throw new Error(`Failed to resolve home directory for path: ${remotePath}. ${err.message}`);
|
|
381
402
|
}
|
|
382
403
|
}
|
|
383
|
-
|
|
404
|
+
|
|
384
405
|
const sftp = await this.getSFTP();
|
|
385
406
|
return new Promise((resolve, reject) => {
|
|
386
407
|
sftp.fastGet(resolvedRemotePath, localPath, (err) => {
|
|
@@ -393,7 +414,7 @@ class SSHManager {
|
|
|
393
414
|
async putFiles(files, options = {}) {
|
|
394
415
|
const sftp = await this.getSFTP();
|
|
395
416
|
const results = [];
|
|
396
|
-
|
|
417
|
+
|
|
397
418
|
for (const file of files) {
|
|
398
419
|
try {
|
|
399
420
|
await this.putFile(file.local, file.remote);
|
|
@@ -403,7 +424,7 @@ class SSHManager {
|
|
|
403
424
|
if (options.stopOnError) break;
|
|
404
425
|
}
|
|
405
426
|
}
|
|
406
|
-
|
|
427
|
+
|
|
407
428
|
return results;
|
|
408
429
|
}
|
|
409
430
|
|
|
@@ -432,4 +453,4 @@ class SSHManager {
|
|
|
432
453
|
}
|
|
433
454
|
}
|
|
434
455
|
|
|
435
|
-
export default SSHManager;
|
|
456
|
+
export default SSHManager;
|