node-ssh
Advanced tools
Comparing version 0.2.7 to 0.2.8
329
Dist/SSH.js
@@ -1,110 +0,223 @@ | ||
# @Compiler-Output "../Dist/SSH.js" | ||
// Generated by CoffeeScript 1.9.3 | ||
(function() { | ||
var Driver, FS, Path, Promise, SSH; | ||
FS = require 'fs' | ||
Driver = require 'ssh2' | ||
Path = require 'path' | ||
Promise = require 'a-promise' | ||
FS = require('fs'); | ||
class SSH | ||
constructor:(Config)-> | ||
@Config = Config | ||
if typeof Config.username is 'undefined' then throw new Error "Please specify a valid Username" | ||
if typeof Config.host is 'undefined' then throw new Error "Please specify a valid Host" | ||
if Config.privateKey | ||
if Path.isAbsolute(Config.privateKey) | ||
try | ||
Config.privateKey = FS.readFileSync Config.privateKey | ||
catch | ||
throw new Error "Unable to read the Private Key File" | ||
else if typeof Config.password is 'undefined' | ||
throw new Error "Please specify a valid password or Private Key" | ||
Config.port = Config.port || 22 | ||
@Connected = false | ||
connect:-> | ||
@Connection = new Driver() | ||
return new Promise (Resolve, Reject)=> | ||
try | ||
@Connection.on 'error', Reject | ||
@Connection.on 'ready', => | ||
@Connected = true | ||
Resolve() | ||
@Connection.connect(@Config) | ||
catch error | ||
Reject error | ||
mkdir:(Path)-> | ||
return @exec("mkdir -p #{Path}") | ||
exec:(Command, Opts)-> | ||
throw new Error("Please connect before doing anything else") unless @Connected | ||
Opts = Opts || {} | ||
return new Promise (Resolve, Reject)=> | ||
Command = "cd #{Opts.cwd}; #{Command}" if Opts.cwd | ||
@Connection.exec Command, (Error, Stream)=> | ||
return Reject(Error) if Error | ||
ToReturn = stdout: [], stderr: [] | ||
Stream.on('close', -> | ||
Resolve stderr: ToReturn.stderr.join(""), stdout: ToReturn.stdout.join("") | ||
).on('data', (Data)-> | ||
ToReturn.stdout.push Data.toString() | ||
).stderr.on('data', (Data)-> | ||
ToReturn.stderr.push Data.toString() | ||
) | ||
put:(LocalFile, RemoteFile, SFTP, Retry = true)-> | ||
throw new Error("Please connect before doing anything else") unless @Connected | ||
return new Promise (Resolve, Reject)=> | ||
try | ||
FS.accessSync(LocalFile, FS.R_OK) | ||
catch | ||
return Reject("Local File '#{LocalFile}' doesn't exist") | ||
if SFTP | ||
ThePromise = Promise.resolve(SFTP) | ||
else | ||
ThePromise = @requestSFTP() | ||
ThePromise.then (SFTP)=> | ||
SFTP.fastPut LocalFile, RemoteFile, (Error)=> | ||
return Resolve() unless Error | ||
return Reject(Error) if Error.message isnt 'No such file' or not Retry | ||
@mkdir(RemoteFile.split("/").slice(0,-1).join('/')).then => | ||
@put(LocalFile, RemoteFile, SFTP, false) | ||
putMulti:(Files, SFTP)-> | ||
throw new Error("Please connect before doing anything else") unless @Connected | ||
return new Promise (Resolve, Reject)=> | ||
if SFTP | ||
ThePromise = Promise.resolve(SFTP) | ||
else | ||
ThePromise = @requestSFTP() | ||
Promises = [] | ||
ThePromise.then (SFTP)=> | ||
Files.forEach (File)=> | ||
return unless File.Local or File.Remote | ||
return unless FS.existsSync File.Local | ||
Promises.push @put(File.Local, File.Remote, SFTP) | ||
Promise.all(Promises).then(Resolve,Reject); | ||
get:(RemoteFile, LocalFile, SFTP)-> | ||
throw new Error("Please connect before doing anything else") unless @Connected | ||
return new Promise (Resolve, Reject)=> | ||
if SFTP | ||
ThePromise = Promise.resolve(SFTP) | ||
else | ||
ThePromise = @requestSFTP() | ||
ThePromise.then (SFTP)=> | ||
Stream = SFTP.createReadStream RemoteFile | ||
Contents = [] | ||
Stream.on('data', (Data)-> | ||
Contents.push Data.toString() | ||
).on('close', -> | ||
Contents = Contents.join('') | ||
return Resolve(Contents) unless LocalFile | ||
FS.writeFile LocalFile, Contents, (error)-> | ||
return Reject(error) if error | ||
Resolve() | ||
) | ||
requestSFTP:-> | ||
throw new Error("Please connect before doing anything else") unless @Connected | ||
return new Promise (Resolve, Reject)=> | ||
@Connection.sftp (Error, SFTP)=> | ||
return Reject(Error) if Error | ||
Resolve(SFTP); | ||
end:-> | ||
@Connection.end() | ||
@Connected = false | ||
module.exports = SSH | ||
Driver = require('ssh2'); | ||
Path = require('path'); | ||
Promise = require('a-promise'); | ||
SSH = (function() { | ||
function SSH(Config) { | ||
this.Config = Config; | ||
if (typeof Config.username === 'undefined') { | ||
throw new Error("Please specify a valid Username"); | ||
} | ||
if (typeof Config.host === 'undefined') { | ||
throw new Error("Please specify a valid Host"); | ||
} | ||
if (Config.privateKey) { | ||
if (Path.isAbsolute(Config.privateKey)) { | ||
try { | ||
Config.privateKey = FS.readFileSync(Config.privateKey); | ||
} catch (_error) { | ||
throw new Error("Unable to read the Private Key File"); | ||
} | ||
} | ||
} else if (typeof Config.password === 'undefined') { | ||
throw new Error("Please specify a valid password or Private Key"); | ||
} | ||
Config.port = Config.port || 22; | ||
this.Connected = false; | ||
} | ||
SSH.prototype.connect = function() { | ||
this.Connection = new Driver(); | ||
return new Promise((function(_this) { | ||
return function(Resolve, Reject) { | ||
var error; | ||
try { | ||
_this.Connection.on('error', Reject); | ||
_this.Connection.on('ready', function() { | ||
_this.Connected = true; | ||
return Resolve(); | ||
}); | ||
return _this.Connection.connect(_this.Config); | ||
} catch (_error) { | ||
error = _error; | ||
return Reject(error); | ||
} | ||
}; | ||
})(this)); | ||
}; | ||
SSH.prototype.mkdir = function(Path) { | ||
return this.exec("mkdir -p " + Path); | ||
}; | ||
SSH.prototype.exec = function(Command, Opts) { | ||
if (!this.Connected) { | ||
throw new Error("Please connect before doing anything else"); | ||
} | ||
Opts = Opts || {}; | ||
return new Promise((function(_this) { | ||
return function(Resolve, Reject) { | ||
if (Opts.cwd) { | ||
Command = "cd " + Opts.cwd + "; " + Command; | ||
} | ||
return _this.Connection.exec(Command, function(Error, Stream) { | ||
var ToReturn; | ||
if (Error) { | ||
return Reject(Error); | ||
} | ||
ToReturn = { | ||
stdout: [], | ||
stderr: [] | ||
}; | ||
return Stream.on('close', function() { | ||
return Resolve({ | ||
stderr: ToReturn.stderr.join(""), | ||
stdout: ToReturn.stdout.join("") | ||
}); | ||
}).on('data', function(Data) { | ||
return ToReturn.stdout.push(Data.toString()); | ||
}).stderr.on('data', function(Data) { | ||
return ToReturn.stderr.push(Data.toString()); | ||
}); | ||
}); | ||
}; | ||
})(this)); | ||
}; | ||
SSH.prototype.put = function(LocalFile, RemoteFile, SFTP, Retry) { | ||
if (Retry == null) { | ||
Retry = true; | ||
} | ||
if (!this.Connected) { | ||
throw new Error("Please connect before doing anything else"); | ||
} | ||
return new Promise((function(_this) { | ||
return function(Resolve, Reject) { | ||
var ThePromise; | ||
try { | ||
FS.accessSync(LocalFile, FS.R_OK); | ||
} catch (_error) { | ||
return Reject("Local File '" + LocalFile + "' doesn't exist"); | ||
} | ||
if (SFTP) { | ||
ThePromise = Promise.resolve(SFTP); | ||
} else { | ||
ThePromise = _this.requestSFTP(); | ||
} | ||
return ThePromise.then(function(SFTP) { | ||
return SFTP.fastPut(LocalFile, RemoteFile, function(Error) { | ||
if (!Error) { | ||
return Resolve(); | ||
} | ||
if (Error.message !== 'No such file' || !Retry) { | ||
return Reject(Error); | ||
} | ||
return _this.mkdir(RemoteFile.split("/").slice(0, -1).join('/')).then(function() { | ||
return _this.put(LocalFile, RemoteFile, SFTP, false); | ||
}); | ||
}); | ||
}); | ||
}; | ||
})(this)); | ||
}; | ||
SSH.prototype.putMulti = function(Files, SFTP) { | ||
if (!this.Connected) { | ||
throw new Error("Please connect before doing anything else"); | ||
} | ||
return new Promise((function(_this) { | ||
return function(Resolve, Reject) { | ||
var Promises, ThePromise; | ||
if (SFTP) { | ||
ThePromise = Promise.resolve(SFTP); | ||
} else { | ||
ThePromise = _this.requestSFTP(); | ||
} | ||
Promises = []; | ||
return ThePromise.then(function(SFTP) { | ||
Files.forEach(function(File) { | ||
if (!(File.Local || File.Remote)) { | ||
return; | ||
} | ||
if (!FS.existsSync(File.Local)) { | ||
return; | ||
} | ||
return Promises.push(_this.put(File.Local, File.Remote, SFTP)); | ||
}); | ||
return Promise.all(Promises).then(Resolve, Reject); | ||
}); | ||
}; | ||
})(this)); | ||
}; | ||
SSH.prototype.get = function(RemoteFile, LocalFile, SFTP) { | ||
if (!this.Connected) { | ||
throw new Error("Please connect before doing anything else"); | ||
} | ||
return new Promise((function(_this) { | ||
return function(Resolve, Reject) { | ||
var ThePromise; | ||
if (SFTP) { | ||
ThePromise = Promise.resolve(SFTP); | ||
} else { | ||
ThePromise = _this.requestSFTP(); | ||
} | ||
return ThePromise.then(function(SFTP) { | ||
var Contents, Stream; | ||
Stream = SFTP.createReadStream(RemoteFile); | ||
Contents = []; | ||
return Stream.on('data', function(Data) { | ||
return Contents.push(Data.toString()); | ||
}).on('close', function() { | ||
Contents = Contents.join(''); | ||
if (!LocalFile) { | ||
return Resolve(Contents); | ||
} | ||
return FS.writeFile(LocalFile, Contents, function(error) { | ||
if (error) { | ||
return Reject(error); | ||
} | ||
return Resolve(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
})(this)); | ||
}; | ||
SSH.prototype.requestSFTP = function() { | ||
if (!this.Connected) { | ||
throw new Error("Please connect before doing anything else"); | ||
} | ||
return new Promise((function(_this) { | ||
return function(Resolve, Reject) { | ||
return _this.Connection.sftp(function(Error, SFTP) { | ||
if (Error) { | ||
return Reject(Error); | ||
} | ||
return Resolve(SFTP); | ||
}); | ||
}; | ||
})(this)); | ||
}; | ||
SSH.prototype.end = function() { | ||
this.Connection.end(); | ||
return this.Connected = false; | ||
}; | ||
return SSH; | ||
})(); | ||
module.exports = SSH; | ||
}).call(this); |
{ | ||
"name": "node-ssh", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"description": "SS2 with Promises", | ||
@@ -26,6 +26,3 @@ "main": "Dist/SSH.js", | ||
"a-promise": "latest" | ||
}, | ||
"scripts":{ | ||
"prepublish": "mkdir -p Dist; uc-compile Source/SSH.coffee > Dist/SSH.js" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
13483
206
1
3