Comparing version 0.2.10 to 1.0.0
137
Dist/SSH.js
@@ -95,2 +95,3 @@ (function() { | ||
SSH.prototype.put = function(LocalFile, RemoteFile, SFTP, Retry) { | ||
var ThePromise; | ||
if (Retry == null) { | ||
@@ -102,28 +103,30 @@ Retry = true; | ||
} | ||
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(); | ||
try { | ||
FS.accessSync(LocalFile, FS.R_OK); | ||
} catch (_error) { | ||
throw new Error("Local File '" + LocalFile + "' doesn't exist"); | ||
} | ||
if (SFTP) { | ||
ThePromise = Promise.resolve(SFTP); | ||
} else { | ||
ThePromise = this.requestSFTP(); | ||
} | ||
return ThePromise.then((function(_this) { | ||
return function(SFTP) { | ||
var Deferred; | ||
Deferred = Promise.defer(); | ||
SFTP.fastPut(LocalFile, RemoteFile, function(Error) { | ||
if (Error) { | ||
if (Error.message === 'No such file' && !Retry) { | ||
return Deferred.reject(Error); | ||
} else { | ||
return Deferred.resolve(_this.mkdir(RemoteFile.split("/").slice(0, -1).join('/')).then(function() { | ||
return _this.put(LocalFile, RemoteFile, SFTP, false); | ||
})); | ||
} | ||
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); | ||
}); | ||
}); | ||
} else { | ||
return Deferred.resolve(); | ||
} | ||
}); | ||
return Deferred.promise; | ||
}; | ||
@@ -134,26 +137,24 @@ })(this)); | ||
SSH.prototype.putMulti = function(Files, SFTP) { | ||
var Promises, ThePromise; | ||
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); | ||
if (SFTP) { | ||
ThePromise = Promise.resolve(SFTP); | ||
} else { | ||
ThePromise = this.requestSFTP(); | ||
} | ||
Promises = []; | ||
return ThePromise.then((function(_this) { | ||
return 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); | ||
}; | ||
@@ -164,32 +165,32 @@ })(this)); | ||
SSH.prototype.get = function(RemoteFile, LocalFile, SFTP) { | ||
var ThePromise; | ||
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); | ||
if (SFTP) { | ||
ThePromise = Promise.resolve(SFTP); | ||
} else { | ||
ThePromise = this.requestSFTP(); | ||
} | ||
return ThePromise.then((function(_this) { | ||
return function(SFTP) { | ||
var Contents, Deferred, Stream; | ||
Deferred = Promise.defer(); | ||
Stream = SFTP.createReadStream(RemoteFile); | ||
Contents = []; | ||
Stream.on('data', function(Data) { | ||
return Contents.push(Data.toString()); | ||
}).on('close', function() { | ||
Contents = Contents.join(''); | ||
if (!LocalFile) { | ||
return Deferred.resolve(Contents); | ||
} | ||
return FS.writeFile(LocalFile, Contents, function(error) { | ||
if (error) { | ||
return Reject(error); | ||
} | ||
return FS.writeFile(LocalFile, Contents, function(error) { | ||
if (error) { | ||
return Reject(error); | ||
} | ||
return Resolve(); | ||
}); | ||
return Deferred.resolve(); | ||
}); | ||
}); | ||
return Deferred.promise; | ||
}; | ||
@@ -196,0 +197,0 @@ })(this)); |
{ | ||
"name": "node-ssh", | ||
"version": "0.2.10", | ||
"version": "1.0.0", | ||
"description": "SS2 with Promises", | ||
@@ -5,0 +5,0 @@ "main": "Dist/SSH.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
221
2
14099