여러개의 FTP Get을 하면 Error 메세지(Unable to make data connection )가 발생합니다.
조회수 1939회
Node.js의 ftp module을 통해서 동시에 여러개의 file을 다운 받는 것을 구현하려 합니다. 잘 될때도 있고 안될때도 있는데..
디버깅 해본 결과 1개의 파일 Get이 끝나기 전에 다음 파일의 Get을 시작하면 Unable to make data connection 메세지가 발생하면서 FTP가 끊깁니다.
뭔가 Sync를 맞춰서 해야할 것 같은데.. 조언 부탁드립니다.
var c = new Client();
c.on('ready', function() {
c.list(remote_path, function(err, list) {
if (err) throw err;
for(var i=0; i<list.length; i++){
if(list[i].type === 'd'){
if (list[i].name != '.' && list[i].name != '..'){
if(list[i].name.search(search_pattern) != -1){
folders.push(list[i].name);
}
}
}
}
console.log(folders.length + ' folders'); //: ' + folders);
for(let i=0; i<folders.length; i++){ // using 'let' for closure problem
fs.mkdir(local_path+'/'+folders[i], function(err){
});
c.list(remote_path+'/'+folders[i], function(err, list) {
NumFiles += list.length;
list.forEach(function (element, index, array) {
c.get(remote_path+'/'+folders[i]+'/'+element.name, function (err, stream) {
stream.once('close', function () { c.end(); console.log('Connection Ended.'); });
stream.pipe(fs.createWriteStream(local_path+'/'+folders[i]+'/'+element.name));
LoadedFiles++;
console.log('Progress : '+LoadedFiles+'/'+NumFiles);
});
});
});
}
});
});
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력