5 ms·
> The bug is that there's not a closure around the ssh instance, so if you call this function multiple times it'll actually return the same connection instance.
by minitech 3y ago
> The bug is that there's not a closure around the ssh instance, so if you call this function multiple times it'll actually return the same connection instance.
I’m not entirely sure what you mean by this, but it doesn’t sound like a correct diagnosis. Each call to `getSFTPConnection` creates a new `ssh2.Client` instance (unless `ssh2.Client`’s constructor does something really weird), and the promise can only resolve with the value `ssh.sftp` passes.
(The error handling does look broken, though – I would expect the 'error' event to be able to fire at any time, and the `ssh.sftp` callback is missing a check.)
- claytongulick 3y agoYes, you're 100% correct, I mixed some stuff up when I was posting the code for simplicity. Bad example!