使用用户名和密码连接 示例代码
const Client = require('ssh2-sftp-client');
module.exports = class SFTPClient {
#sftpClient;
constructor() {
this.#sftpClient = new Client();
}
async connect(options) {
try {
return this.#sftpClient.connect(options);
} catch (err) {
return null;
}
}
}
连接最初运行正常,但现在 lambda 函数失败,而 ECS 实例继续正常运行。
这是来自 Lambda 的详细日志
2024-10-29T21:37:39.289Z b2a4f522-527d-4bbe-ae4f-116600d2bd76 INFO Debug: CLIENT[sftp]: ssh2-sftp-client Version: 9.0.4
{
"node": "16.20.2",
"v8": "9.4.146.26-node.26",
"uv": "1.43.0",
"zlib": "1.2.11",
"brotli": "1.0.9",
"ares": "1.19.1",
"modules": "93",
"nghttp2": "1.47.0",
"napi": "8",
"llhttp": "6.0.11",
"openssl": "1.1.1v+quic",
"cldr": "41.0",
"icu": "71.1",
"tz": "2022f",
"unicode": "14.0",
"ngtcp2": "0.8.1",
"nghttp3": "0.7.0"
}
2024-10-29T21:37:39.290Z b2a4f522-527d-4bbe-ae4f-116600d2bd76 INFO Debug: CLIENT[sftp]: connect: Connect attempt 1
2024-10-29T21:37:39.293Z b2a4f522-527d-4bbe-ae4f-116600d2bd76 INFO Debug: Custom crypto binding not available
2024-10-29T21:37:39.771Z b2a4f522-527d-4bbe-ae4f-116600d2bd76 INFO Debug: Verifying signature ...
2024-10-29T21:37:39.772Z b2a4f522-527d-4bbe-ae4f-116600d2bd76 INFO Debug: Verified signature
2024-10-29T21:37:39.773Z b2a4f522-527d-4bbe-ae4f-116600d2bd76 INFO Debug: Handshake completed
2024-10-29T21:37:39.773Z b2a4f522-527d-4bbe-ae4f-116600d2bd76 INFO #sftpClient event handshake:
{
"kex": "ecdh-sha2-nistp256",
"serverHostKey": "ssh-ed25519",
"cs": {
"cipher": "[email protected]",
"mac": "",
"compress": "none",
"lang": ""
},
"sc": {
"cipher": "[email protected]",
"mac": "",
"compress": "none",
"lang": ""
}
}
2024-10-29T21:37:39.898Z b2a4f522-527d-4bbe-ae4f-116600d2bd76 INFO Debug: Outbound: Sending USERAUTH_REQUEST (none)
2024-10-29T21:37:40.086Z b2a4f522-527d-4bbe-ae4f-116600d2bd76 INFO Debug: Socket error: read ECONNRESET
2024-10-29T21:37:40.087Z b2a4f522-527d-4bbe-ae4f-116600d2bd76 INFO #sftpClient event error: Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read',
level: 'client-socket'
}
我们也尝试过使用 Node v20 和 ssh2 v1.16.0,但也失败了。