Closed deeppaifacctum closed 9 months ago
THe problem is with the use of asyunc/await and .forEach. The array methods like .forEach, .reduce, .map, .filter etc are NOT async/await safe. While it is possible to use these constructs, you have to structure your code in a psecific manner to get reliable results and this aditional overhead tyupically makes the use of .forEach et. al. less clear, more error prone and more complicated than using a standard for loop.
There is lots on this (and how you can structure your code to use .forEach if you really really want to) to bb found on the web and a quick google search will find you plenty of details if interested.
Just refactor your code to use standard loops and you should be OK.
I am trying to get multiple files from sftp server using this code:
The above fails with this error:
The same code works if the forEach is removed. Same is observed if the sftp.get is in another async function say 'downloadFile' with the same error.
"ssh2-sftp-client": "^9.1.0"