I use ssh2-sftp-client to get some files. If I use sftp.end(); at the end I get this error in the console:
{ Error: fastGet->exists->exists: No SFTP connection available
at Object.formatError (/home/project/node_modules/ssh2-sftp-client/src/utils.js:62:18)
at SftpClient.fastGet (/home/project/node_modules/ssh2-sftp-client/src/index.js:590:19)
at process._tickCallback (internal/process/next_tick.js:68:7) code: 'ERR_NOT_CONNECTED', custom: true } 'Error'
...
What am I missing?
I use ssh2-sftp-client to get some files. If I use sftp.end(); at the end I get this error in the console:
{ Error: fastGet->exists->exists: No SFTP connection available
at Object.formatError (/home/project/node_modules/ssh2-sftp-client/src/utils.js:62:18)
at SftpClient.fastGet (/home/project/node_modules/ssh2-sftp-client/src/index.js:590:19)
at process._tickCallback (internal/process/next_tick.js:68:7) code: 'ERR_NOT_CONNECTED', custom: true } 'Error'
...
What am I missing?
Share Improve this question edited Jun 11, 2020 at 17:55 Philipp M asked Jun 10, 2020 at 17:06 Philipp MPhilipp M 3,5085 gold badges43 silver badges101 bronze badges1 Answer
Reset to default 5What I believe is currently happening is that since you're not returning a Promise
from your second then()
, the third then()
gets resolved immediately (with a value of undefined
), which causes your connection to get terminated immediately (before your fastGet()
s have time to finish).
To fix this, you would need to explicitly return a Promise
from your second then()
that only gets resolved once all of the files have been transferred. You may also want to consider rejecting that promise if at least one of the transfers fails.