我正在尝试使用 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