Comparing version 0.1.1 to 0.1.2
@@ -11,3 +11,3 @@ const fs = require('fs'); | ||
class NeoScp extends EventEmitter { | ||
constructor (connection) { | ||
constructor(connection) { | ||
super(); | ||
@@ -17,3 +17,3 @@ this.conn = connection; | ||
debug (data) { | ||
debug(data) { | ||
this.emit('debug', data); | ||
@@ -30,3 +30,3 @@ } | ||
*/ | ||
putFile (localFile, remoteFile, callback) { | ||
putFile(localFile, remoteFile, callback) { | ||
let self = this; | ||
@@ -76,2 +76,49 @@ | ||
/** | ||
* Gets a file from host | ||
* | ||
* @param {string} remoteFile | ||
* @param {string} localFile | ||
* @param {function} callback | ||
* @memberof NeoScp | ||
*/ | ||
getFile(remoteFile, localFile, callback) { | ||
let self = this; | ||
self.conn.exec(`scp -f ${remoteFile}`, (err, stream) => { | ||
if (err) callback(err); | ||
let fileBuffer = Buffer.from([0]); | ||
stream.write(Buffer.from([0])); | ||
stream.on('close', () => { | ||
self.debug('Stream close'); | ||
fs.writeFileSync(localFile, fileBuffer.slice(1, -1)); | ||
stream.end(); | ||
callback(); | ||
}); | ||
let jump = 0; | ||
stream.on('data', (data) => { | ||
stream.write(Buffer.from([0])); | ||
if (jump === 0) { | ||
jump = 1; | ||
return; | ||
} | ||
fileBuffer = Buffer.concat([fileBuffer, data]); | ||
self.debug(`STDOUT: "${data}"`); | ||
}); | ||
stream.stderr.on('data', data => { | ||
self.debug(`STDERR: "${data}"`); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Gets the remote file size | ||
@@ -83,3 +130,3 @@ * | ||
*/ | ||
getFileSize (remoteFile, callback) { | ||
getFileSize(remoteFile, callback) { | ||
let self = this; | ||
@@ -86,0 +133,0 @@ self.conn.exec(`ls -la ${remoteFile} | tr -s ' '| cut -d' ' -f5`, (err, stream) => { |
{ | ||
"name": "neo-scp", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A pure JS real scp module based on ssh2 module", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha" | ||
}, | ||
@@ -24,3 +24,6 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/Fabio286/neo-scp#readme" | ||
"homepage": "https://github.com/Fabio286/neo-scp#readme", | ||
"dependencies": { | ||
"ssh2": "^0.8.4" | ||
} | ||
} |
@@ -74,3 +74,4 @@ # Neo SCP | ||
Coming soon. | ||
Gets a file from remote host. | ||
You must pass the `remoteFile` path, the `localFile` destination path and a callback function. | ||
@@ -77,0 +78,0 @@ ## Debug |
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
9432
8
136
1
86
1
+ Addedssh2@^0.8.4
+ Addedasn1@0.2.6(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedssh2@0.8.9(transitive)
+ Addedssh2-streams@0.4.10(transitive)
+ Addedstreamsearch@0.1.2(transitive)
+ Addedtweetnacl@0.14.5(transitive)