Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js ssh2 sftp客户端一遍又一遍地获取相同的文件_Node.js_Ssh2 Sftp - Fatal编程技术网

Node.js ssh2 sftp客户端一遍又一遍地获取相同的文件

Node.js ssh2 sftp客户端一遍又一遍地获取相同的文件,node.js,ssh2-sftp,Node.js,Ssh2 Sftp,我正在尝试使用node和ssh2-Sftp客户端从Sftp服务器获取一堆2k文件 ftp.connect({ host: '...', port: '...', username: '...', password: '...', readyTimeout: ... }).then(() => { return ftp.list('/

我正在尝试使用node和ssh2-Sftp客户端从
Sftp
服务器获取一堆2k文件

ftp.connect({
            host: '...',
            port: '...',
            username: '...',
            password: '...',
            readyTimeout: ...
        }).then(() => {
            return ftp.list('/Stmts/')
        }) .then((data) => {
            let filesToTransfer = [];
            //only get files I dont already have
            for (let i = data.length-10; i < data.length; i++) {
                if (!blobs.includes(data[i].name)) {
                     filesToTransfer.push(data[i].name)
                }
            } 
            // Get the files in the filesToTransfer Array
            for (const file of filesToTransfer){
               ftp.fastGet('/Stmts/' + file, 
               path.join(__dirname, '../Files/' + file))
            }
ftp.connect({
主机:“…”,
端口:“…”,
用户名:“…”,
密码:“…”,
readyTimeout:。。。
}).然后(()=>{
返回ftp.list(“/Stmts/”)
})。然后((数据)=>{
让filesToTransfer=[];
//只获取我还没有的文件
for(设i=data.length-10;i
这将成功获取阵列中的文件并正确命名,但每次下载的每个文件实际上都是同一个文件


谢谢

通过执行以下操作解决了此问题:

.then((data)=>{
 var x = 0;
        var loop = function (arr) {
            let file = arr[x].name;
            let remoteFileNameWithPath = '/Stmts/' + file;
            let localFilePath = path.join(__dirname, '../Files/' + file)
            ftp.fastGet(remoteFileNameWithPath, localFilePath).then((a) => {                    
                x++
                if (x < arr.length) {
                    loop(arr)
                } 
            })
        }
 })
loop(data)
。然后((数据)=>{
var x=0;
var回路=功能(arr){
让file=arr[x].name;
让remoteFileNameWithPath='/Stmts/'+文件;
让localFilePath=path.join(_dirname,'../Files/'+file)
fastGet(remoteFileNameWithPath,localFilePath)。然后((a)=>{
x++
如果(x