0

Sftp我试图从使用节点的服务器获取一堆 2k 文件和ssh2-sftp-client.

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

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

谢谢

4

1 回答 1

0

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

.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)
于 2018-08-23T03:35:50.983 回答