'Nodejs getting error while download files using FTP

I am using node-ftp package for FTP connection. Below code example

const FTPClient = require('ftp');
const fs = require("fs");
let ftp_client = new FTPClient();
let ftpConfig = {
    host: '94.200.190.184',
    port: 21,
    user: '99*******',
    password: '******'
}

var downloadList = [];
//create a connection to ftp server
ftp_client.connect(ftpConfig);
//list directory and files from server.
ftp_client.on('ready', function() { 
    ftp_client.list('Gracenote',function(err, list) {
        if (err) throw err;
        list.map(function(entry){
            console.log(entry.name);
            if (entry.name !== '.' || entry.name !== '..') {
                downloadList.push(entry.name);
             }
        });
    downloadList.map(function(file, index){
      console.log(file);
      // Download remote files and save it to the local file system:
      ftp_client.get('Gracenote/' + file, function(err, stream) {

        if (err) throw err;
        stream.once('close', function() { ftp_client.end(); });
        stream.pipe(fs.createWriteStream(file));

      });
    });
    ftp_client.end();
    });
  });

I am getting error like: enter image description here

Is their is any way we can download files using batch process



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source