Skip to content
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
13 changes: 11 additions & 2 deletions lib/jsftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ const expectedMarks = {
const RE_PASV = /([-\d]+,[-\d]+,[-\d]+,[-\d]+),([-\d]+),([-\d]+)/;
const FTP_NEWLINE = /\r\n|\n/;

function isReadableStream(stream) {
return stream !== null &&
typeof stream === 'object' &&
typeof stream.pipe === 'function' &&
stream.readable !== false &&
typeof stream._read === 'function' &&
typeof stream._readableState === 'object';
}

function runCmd(name, ...params) {
let callback = NOOP;
let completeCmd = name + " ";
Expand Down Expand Up @@ -565,7 +574,7 @@ Ftp.prototype.put = function(from, destination, callback) {
const totalSize = err ? 0 : stats.size;
putReadable(fs.createReadStream(from), destination, totalSize);
});
} else if (from instanceof stream.Readable) {
} else if (isReadableStream(from)) {
putReadable(from, destination, 0);
} else {
callback(
Expand Down Expand Up @@ -604,7 +613,7 @@ Ftp.prototype.getPutSocket = function(from, path, next) {
this.pasvTimeout(socket, next);
if (from instanceof Buffer) {
socket.end(from);
} else if (from instanceof stream.Readable) {
} else if (isReadableStream(from)) {
from.pipe(socket);
}
} else {
Expand Down