You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Lambda函数SFTP连接失败(ECS可正常连接)技术求助

Lambda函数无法连接SFTP服务器,但ECS实例连接正常(ssh2-sftp-client)

环境信息

  • Node: 16
  • ssh2-sftp-client: 9

连接方式

使用用户名&密码连接

示例代码

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); // options = {host,port,username,password}
    } 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": "aes128-gcm@openssh.com",
        "mac": "",
        "compress": "none",
        "lang": ""
    },
    "sc": {
        "cipher": "aes128-gcm@openssh.com",
        "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,但仍然失败。


内容的提问来源于stack exchange,提问作者Abdullah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 14:05:57