gpt4 book ai didi

Node.js ssh2-sftp-客户端错误 : fastPut: No response from server Local

转载 作者:行者123 更新时间:2023-12-05 02:40:39 25 4
gpt4 key购买 nike

我正在使用 node -v v14.17.0"ssh2-sftp-client": "^7.0.0" 和方法 fastPut https://github.com/theophilusx/ssh2-sftp-client#sec-5-2-9

检查远程文件没问题,所以连接正常。

我的环境是wsl2 Ubuntu-20.04

我遇到的问题是错误

RuntimeError: abort(Error: fastPut: No response from server Local: /home/draganddrop/testi.txt Remote: Downloads/testi.txt). Build with -s ASSERTIONS=1 for more info.
at process.J (/home/draganddrop/node_modules/ssh2/lib/protocol/crypto/poly1305.js:20:53)
at process.emit (events.js:376:20)
at processPromiseRejections (internal/process/promises.js:245:33)
at processTicksAndRejections (internal/process/task_queues.js:96:32)

我也尝试过从控制台使用 sftp> put/home/draganddrop/testi.txt Downloads/testi.txt,效果很好。

我正在使用的代码:

        let Client = require('ssh2-sftp-client');
let sftp = new Client();

let remotePath = 'Downloads/testi.txt';
let localPath = '/home/draganddrop/testi.txt'

const config = {
host: 'XX.XX.XXX.XXX',
port: '22',
username: 'XXXXX',
password: 'XXXXXX'
};

sftp.connect(config)
.then(() => {
sftp.fastPut(localPath, remotePath);
//return sftp.exists(remotePath);
})
//.then(data => {
// console.log(data); // will be false or d, -, l (dir, file or link)
//})
.then(() => {
sftp.end();
})
.catch(err => {
console.error(err.message);
});

我不知道是什么导致了这个错误,我尝试了不同的路径并得到了错误的路径错误或这个。可能是什么原因?

最佳答案

问题的原因是连接在执行完fastPut之前关闭。
您正在运行连接,之后在第一个 .then 中,方法 fastPut 异步运行,它不会等待完成执行并返回 undefined 到下一个方法 .then 链的
要解决这个问题,您只需要返回从 fastPut

收到的 promise
sftp.connect(config)
.then(() => sftp.fastPut(localPath, remotePath))
.then((data) => {/* do something*/}
.finally(() => sftp.end())

关于Node.js ssh2-sftp-客户端错误 : fastPut: No response from server Local,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68426466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com