【问题标题】:ssh2-sftp-client getting same file over and overssh2-sftp-client 一遍又一遍地获取相同的文件
【发布时间】:2018-08-21 23:38:14
【问题描述】:

我正在尝试使用节点和ssh2-sftp-clientSftp 服务器获取一堆 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))
            }

这成功地获取了数组中的一个文件并正确命名它,除了每个文件实际上每次下载的文件都是同一个文件。

谢谢

【问题讨论】:

    标签: node.js ssh2-sftp


    【解决方案1】:

    通过这样做解决了这个问题:

    .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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 2020-04-06
      • 2018-01-16
      • 2016-12-20
      • 2017-02-15
      • 2019-08-29
      • 1970-01-01
      相关资源
      最近更新 更多