Ich weiß, dass dies ein Async-Rätsel ist, in das ich mich begeben habe, aber ich versuche, mehrere Dateien innerhalb des Callbacks von .list
Methode von einem der verschiedenen FTP-Pakete herunterzuladen.Node FTP: Mehrere asynchrone Anrufe innerhalb der Schleife
So etwas wie diese (Anmerkung: JSFTP hier ist nur ein Wrapper um node-ftp
, ich das gleiche Problem mit, dass man erhalten):
ftp = new JSFTP(conf.FTPConfig)
ftp.ls(conf.remoteFolder, (err, fileList) => {
if (err) return console.error(err)
for (let i=0; i<fileList.length; i++){
file = fileList[i]
ftp.get(file.name, `./Downloaded/${file.name}`, err => {
if (err) return console.error(err)
console.log(`${file.name} copied.`)
})
}
})
Wenn ich nicht eine Schleife verwenden und nur eine Datei herunterladen Alles funktioniert gut. Aber mit einer Schleife, ich bekomme immer folgende Fehler und ich eine der Dateien (außer einer oder zwei leere Datei Platzhalter) nicht bekommen:
(Kurz): Error: 503 Bad sequence of commands
, und weiter unten: 'Probably trying a PASV operation while one is in progress
Es sieht so aus, als ob es alle meine .get
Aufrufe innerhalb der Schleife startet (offensichtlich ohne darauf zu warten, dass einer von ihnen fertig ist, was in Ordnung ist), aber dann alle .get-Aufrufe tatsächlich auf diese Weise ausführt? Sollten sie nicht einfach asynchron parallel laufen?
{ Error: 503 Bad sequence of commands.
at Ftp.parse (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:257:11)
at Ftp.parseResponse (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:174:8)
at Stream.<anonymous> (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:146:24)
at emitOne (events.js:96:13)
at Stream.emit (events.js:188:7)
at ResponseParser.reemit (C:\Git\SenecaFTP\FTPMonitor\node_modules\duplexer\index.js:70:25)
at emitOne (events.js:96:13)
at ResponseParser.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at ResponseParser.Readable.push (_stream_readable.js:130:10) code: 503 }
{ Error: 503 Bad sequence of commands.
at Ftp.parse (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:257:11)
at Ftp.parseResponse (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:174:8)
at Stream.<anonymous> (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:146:24)
at emitOne (events.js:96:13)
at Stream.emit (events.js:188:7)
at ResponseParser.reemit (C:\Git\SenecaFTP\FTPMonitor\node_modules\duplexer\index.js:70:25)
at emitOne (events.js:96:13)
at ResponseParser.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at ResponseParser.Readable.push (_stream_readable.js:130:10) code: 503 }
{ Error: 503 Bad sequence of commands.
at Ftp.parse (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:257:11)
at Ftp.parseResponse (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:174:8)
at Stream.<anonymous> (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:146:24)
at emitOne (events.js:96:13)
at Stream.emit (events.js:188:7)
at ResponseParser.reemit (C:\Git\SenecaFTP\FTPMonitor\node_modules\duplexer\index.js:70:25)
at emitOne (events.js:96:13)
at ResponseParser.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at ResponseParser.Readable.push (_stream_readable.js:130:10) code: 503 }
{ Error: 503 Bad sequence of commands.
at Ftp.parse (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:257:11)
at Ftp.parseResponse (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:174:8)
at Stream.<anonymous> (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:146:24)
at emitOne (events.js:96:13)
at Stream.emit (events.js:188:7)
at ResponseParser.reemit (C:\Git\SenecaFTP\FTPMonitor\node_modules\duplexer\index.js:70:25)
at emitOne (events.js:96:13)
at ResponseParser.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at ResponseParser.Readable.push (_stream_readable.js:130:10) code: 503 }
{ Error: 503 Bad sequence of commands.
at Ftp.parse (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:257:11)
at Ftp.parseResponse (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:174:8)
at Stream.<anonymous> (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:146:24)
at emitOne (events.js:96:13)
at Stream.emit (events.js:188:7)
at ResponseParser.reemit (C:\Git\SenecaFTP\FTPMonitor\node_modules\duplexer\index.js:70:25)
at emitOne (events.js:96:13)
at ResponseParser.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at ResponseParser.Readable.push (_stream_readable.js:130:10) code: 503 }
{ Error: 503 Bad sequence of commands.
at Ftp.parse (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:257:11)
at Ftp.parseResponse (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:174:8)
at Stream.<anonymous> (C:\Git\SenecaFTP\FTPMonitor\node_modules\jsftp\lib\jsftp.js:146:24)
at emitOne (events.js:96:13)
at Stream.emit (events.js:188:7)
at ResponseParser.reemit (C:\Git\SenecaFTP\FTPMonitor\node_modules\duplexer\index.js:70:25)
at emitOne (events.js:96:13)
at ResponseParser.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at ResponseParser.Readable.push (_stream_readable.js:130:10) code: 503 }
{ Error: connect ECONNREFUSED 192.168.100.161:61229
at Object.exports._errnoException (util.js:1007:11)
at exports._exceptionWithHostPort (util.js:1030:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '192.168.100.161',
port: 61229,
msg: 'Probably trying a PASV operation while one is in progress' }
Yea dies sehr geholfen, vielen Dank! Am Ende ging ich die einfache Route, die du oben erwähnt hast. Ich sollte die Async-Bibliothek in Zukunft wahrscheinlich ausprobieren. Aber gerade jetzt wurde das nur für einen Proof of Concept benötigt. Danke noch einmal! – batjko