diff --git a/index.js b/index.js index 37c3e94..7a1d8ed 100644 --- a/index.js +++ b/index.js @@ -173,21 +173,22 @@ class GulpSSH extends EventEmitter { const write = sftp.createWriteStream(filePath, options) write + .on('open', function() { + if (file.isStream()) file.contents.pipe(write) + else if (file.isBuffer()) write.end(file.contents) + else { + err = new PluginError(packageName, 'file error!') + write.end() + } + }) .on('error', function (error) { err = error }) - .on('finish', function () { + .on('close', function () { sftp.end() if (err) callback(err) else callback(null, file) }) - - if (file.isStream()) file.contents.pipe(write) - else if (file.isBuffer()) write.end(file.contents) - else { - err = new PluginError(packageName, 'file error!') - write.end() - } }) }) }, function (callback) { @@ -346,8 +347,8 @@ class GulpSSH extends EventEmitter { let lastCommand commands.forEach(function (command) { - if (command[command.length - 1] !== '\n') command += '\n' log(packageName + ' :: shell :: ' + command) + if (command[command.length - 1] !== '\n') command += '\n' stream.write(command) lastCommand = command }) diff --git a/package.json b/package.json index 807a680..ea287f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-ssh", - "version": "0.7.1", + "version": "0.7.2", "description": "SSH and SFTP tasks for gulp", "license": "MIT", "author": { @@ -32,7 +32,7 @@ "ansicolors": "^0.3.2", "fancy-log": "^1.3.2", "plugin-error": "^1.0.1", - "ssh2": "~0.5.5", + "ssh2": "^1.14.0", "through2": "^2.0.3", "vinyl": "^2.1.0" },