4

i am trying to download each file on ftp server from root folder. what i did is this-

ftpClient.ls(".", function(err, res) { res.forEach(function(file) { console.log(file.name); ftpClient.get("./"+file.name, 'D:/styleinc/ftp/'+file.name, function(hadErr) { if (hadErr) console.log(hadErr); else console.log('File copied successfully!'); }); }); 

but on running it gives me error-

{ [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect', msg: 'Probably trying a PASV operation while one is in progress' } 

i have already successfully logged in and authenticated my self on ftp site..... i don't know what to do please guide me.

1
  • I'm trying to do something almost exactly like you. I believe the issue is we need to wait for one operation to be done before we try another. I think a good example of async control here is around here in the ftpsync package. ftpsync can only be used for uploading though :(. He uses a map limit of 1 to make sure it finishes first. Commented Jan 29, 2016 at 22:46

1 Answer 1

1

This is the chunk of code I used with async.mapLimit to make it work with only one connection concurrently.

'use strict' var JSFtp = require('jsftp'); var inspect = require('util').inspect; var fs = require('fs'); var async = require('async'); var ftp = new JSFtp(require('./util/ftp')) var local = 'EDI/mohawk/OUTBOX/' var remote = 'OUTBOX' var gatherFiles = function(dir){ return new Promise(function(resolve, reject){ ftp.ls(dir + '/*', function(err, res) { if (err) reject(err) console.log(res) var files = []; res.forEach(function(file){ files.push(file.name) }); resolve(files) }) }) } gatherFiles(remote).then(function(files){ console.log(files) async.mapLimit(files, 1, function(file, callback){ console.log('attempting: ' +remote + file + '->' + local + file) ftp.get(remote +'/'+ file, local +'/'+ file, function(err){ if(err){ console.log('Error getting ' + file) callback(err) }else{ console.log('Got ' + file) callback() } }) }, function(err, res){ if(err){ console.log(err) } console.log('updates complete' + res) }) }) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.