Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

Misleading error message "... is not a Buffer" and strange path #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,22 @@ Client.prototype.write = function(options, callback) {

sftp.open(destination, 'w', attrs, function(err, handle) {
if (err) {
// destination is directory
// destination could be a directory
// it eventually can't be accessible
// to prevent getting a destination like:
// /public/app.js/app.js
// we use path.dirname when joining
destination = path.join(
destination, path.basename(options.source)
path.dirname(destination), path.basename(options.source)
);
destination = unixy(destination);

// for emit write event
options.destination = destination;
sftp.open(destination, 'w', attrs, function(err, handle) {
if (err)
throw new Error('There was an error opening the destination: ' + destination
+ '\n' + err + '\n please check the destination file or folder for accessibility');
_write(handle);
});
} else {
Expand Down