I'm interpreting that the code at this point has already decided that the destination isn't absolute so it assumes that its relative, prepends a path, but after calling sftp.open() again it doesn't check the return value of err before calling _write().
The solution could be to check the value of err and act accordingly:
sftp.open(destination, 'w', attrs, function(err, handle) {
if (err)
throw new Error('Destination is invalid');
_write(handle);
});
If the second parameter of .scp, the destination, is invalid it throws an undescriptive (IMHO) error message "handle is not a Buffer".
Example:
...where "/home/blah" doesn't exist.
In client.js at the end of Client.prototype.write() is:
I'm interpreting that the code at this point has already decided that the destination isn't absolute so it assumes that its relative, prepends a path, but after calling sftp.open() again it doesn't check the return value of err before calling _write().
The solution could be to check the value of err and act accordingly: