@jwjp/ftp-mcp 0.7.1 → 0.7.2
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/package.json +1 -1
- package/src/transports.js +35 -5
package/package.json
CHANGED
package/src/transports.js
CHANGED
|
@@ -13,6 +13,31 @@ import { UserError } from './paths.js';
|
|
|
13
13
|
// before it is closed and replaced.
|
|
14
14
|
export const PING_TIMEOUT_MS = 5_000;
|
|
15
15
|
|
|
16
|
+
// Node.js TLS verification failures, such as DEPTH_ZERO_SELF_SIGNED_CERT,
|
|
17
|
+
// CERT_HAS_EXPIRED, or ERR_TLS_CERT_ALTNAME_INVALID.
|
|
18
|
+
const TLS_TRUST_ERROR = /CERT|SELF_SIGNED|UNABLE_TO_(GET|VERIFY)/u;
|
|
19
|
+
|
|
20
|
+
// Connection failures the user can fix get a message that says how. Other
|
|
21
|
+
// errors keep their generic handling, which shows only a code.
|
|
22
|
+
function ftpAccessError(error) {
|
|
23
|
+
if (error?.code === 530) return new UserError('FTP login failed (530). Check REMOTE_USER and REMOTE_PASSWORD.', { cause: error });
|
|
24
|
+
if (typeof error?.code === 'string' && TLS_TRUST_ERROR.test(error.code)) {
|
|
25
|
+
return new UserError(`The FTPS server's certificate could not be verified (${error.code}). If it is signed by a private CA, point NODE_EXTRA_CA_CERTS at that CA, or run Node.js with --use-system-ca. Certificate checks cannot be turned off.`, { cause: error });
|
|
26
|
+
}
|
|
27
|
+
return error;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function sftpAccessError(error) {
|
|
31
|
+
const message = String(error?.message ?? '');
|
|
32
|
+
if (message.includes('Host denied')) {
|
|
33
|
+
return new UserError("The SFTP server's host key does not match SFTP_HOST_KEY_SHA256. Confirm the fingerprint through your hosting provider before changing it; a mismatch can mean the connection is being intercepted.", { cause: error });
|
|
34
|
+
}
|
|
35
|
+
if (error?.level === 'client-authentication' || message.includes('authentication methods failed')) {
|
|
36
|
+
return new UserError('SFTP login failed. Check REMOTE_USER and REMOTE_PASSWORD, or SFTP_PRIVATE_KEY_FILE and SFTP_PASSPHRASE.', { cause: error });
|
|
37
|
+
}
|
|
38
|
+
return error;
|
|
39
|
+
}
|
|
40
|
+
|
|
16
41
|
export class FtpTransport {
|
|
17
42
|
constructor(config, client = new FtpClient(30_000)) {
|
|
18
43
|
this.config = config;
|
|
@@ -20,10 +45,14 @@ export class FtpTransport {
|
|
|
20
45
|
}
|
|
21
46
|
async access() {
|
|
22
47
|
const { host, port, user, password, secure } = this.config;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
48
|
+
try {
|
|
49
|
+
await this.client.access({
|
|
50
|
+
host, port, user, password, secure,
|
|
51
|
+
secureOptions: secure ? { rejectUnauthorized: true, ...(isIP(host) ? {} : { servername: host }) } : undefined
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw ftpAccessError(error);
|
|
55
|
+
}
|
|
27
56
|
}
|
|
28
57
|
async cd(root) { await this.client.cd(root); }
|
|
29
58
|
async ping() {
|
|
@@ -146,7 +175,8 @@ export class SftpTransport {
|
|
|
146
175
|
config.privateKey = await fs.readFile(this.config.sftpPrivateKeyFile);
|
|
147
176
|
if (this.config.sftpPassphrase) config.passphrase = this.config.sftpPassphrase;
|
|
148
177
|
}
|
|
149
|
-
await this.#run('connection', () => this.client.connect(config));
|
|
178
|
+
try { await this.#run('connection', () => this.client.connect(config)); }
|
|
179
|
+
catch (error) { throw sftpAccessError(error); }
|
|
150
180
|
}
|
|
151
181
|
async cd(root) {
|
|
152
182
|
if (await this.#run('root check', () => this.client.exists(root)) !== 'd') throw new UserError('Remote root is not a directory.');
|