我正在尝试通过 SSH2-SFTP-Client (此处)连接 SFTP 服务器。我无法解决这个问题:
我的样板代码:
let Client = require('ssh2-sftp-client');
const fs = require("fs")
require('dotenv').config()
let sftp = new Client()
sftp.connect({
host: process.env.HOST,
port: 22,
username: process.env.USERNAME,
password: process.env.PASSWORD,
debug: console.log,
privateKey: fs.readFileSync('./pvtkey.pem', {
encoding: "utf8"
})
}).then(() => {
return sftp.list('/pathname');
}).then(data => {
console.log(data, 'the data info');
}).catch(err => {
console.log(err, 'catch error');
});
我尝试使用 PPK 和 PEM 文件,但要知道使用。我是 SFTP 新手,所以我无法推断出错误。