3

我正在尝试使用 Firebase Cloud Functions 将文件发送到 webtrends ftp 服务器,但我遇到了一个无法解决的问题。由于我使用 Firebase Cloud Functions,因此我的函数是从 nodejs 服务器运行的。我正在使用这个 npm 包:https ://www.npmjs.com/package/ssh2-sftp-client 。

在线阅读并解释调试日志后,我理解问题在于服务器使用了不推荐使用的加密算法(ssh-dss)。我在这里读到https://www.openssh.com/legacy.html ssh-dss 是遗留的,因此 ssh2 不支持。

我发现的大多数其他解决方案都告诉我配置 ssh 配置,但在这种情况下我无权访问远程并且无法配置它。

这是我用来连接的代码:

const Client = require('ssh2-sftp-client');
const sftp = new Client();
sftp.connect({
  host: 'sftp.webtrends.com',
  port: '****', // omitted
  username: '****', // omitted
  password: '****', // omitted
  algorithms: {
    serverHostKeys: ['ssh-dss'],
  },
});

这是调试日志:

DEBUG: Local ident: 'SSH-2.0-ssh2js0.1.20'
DEBUG: Client: Trying sftp.webtrends.com on port **** ...
DEBUG: Client: Connected
DEBUG: Parser: IN_INIT
DEBUG: Parser: IN_GREETING
DEBUG: Parser: IN_HEADER
DEBUG: Remote ident: 'SSH-2.0-1.82_sshlib GlobalSCAPE'
DEBUG: Parser: IN_PACKET
DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
DEBUG: Parser: IN_PACKETDATA
DEBUG: Parser: IN_PACKETDATAAFTER, packet: KEXINIT
DEBUG: Comparing KEXINITs ...
DEBUG: (remote) KEX algorithms: diffie-hellman-group14-sha1,diffie-hellman-
group-exchange-sha1,diffie-hellman-group1-sha1
DEBUG: (local) KEX algorithms: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-
sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
DEBUG: (local) Host key formats: ssh-rsa,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
DEBUG: Outgoing: Writing KEXINIT
DEBUG: Parser: pktLen:484,padLen:11,remainLen:480
DEBUG: Outgoing: Writing DISCONNECT (KEY_EXCHANGE_FAILED)
DEBUG: KEX algorithm: diffie-hellman-group14-sha1
DEBUG: (remote) Host key formats: ssh-dss
DEBUG: No matching host key format
4

2 回答 2

5

您的配置选项中有错字。按照文档中的说明使用这些设置,它可能会起作用:

algorithms: {
  serverHostKey: ['ssh-dss'], // serverHostKey, without the 's'
},
于 2018-09-07T11:23:54.320 回答
0

因此,如果您无法配置服务器,并且 ssh2-sftp-client 说它们不支持 ssh-dss,那么您唯一的选择是不使用 ssh2-sftp-client,而是使用另一个支持 ssh-dss 的软件包。

用 Google 快速搜索nodejs ftp client "ssh-dss"一下,应该不难找到支持 ssh-dss 的,例如yocto-sftp

于 2018-03-14T08:58:09.920 回答