sftp-promises
Advanced tools
Comparing version 1.0.1 to 1.0.2
21
index.js
var Client = require('ssh2').Client; | ||
var MODES = require('ssh2').SFTP_OPEN_MODE; | ||
// var Promise = require('bluebird'); | ||
@@ -73,10 +74,15 @@ | ||
if (err) { reject(err); conn.end(); return false } | ||
var buffer = Buffer(stat.size); | ||
var bytes = stat.size; | ||
var buffer = Buffer(bytes); | ||
buffer.fill(0); | ||
sftp.read(handle, buffer, 0, buffer.length, 0, function (err) { | ||
if (err) { | ||
var cb = function(err, readBytes, offsetBuffer, position) { | ||
if(err) { | ||
reject(err); | ||
sftp.close(); | ||
conn.end(); | ||
return false; | ||
} else { | ||
} | ||
position = position + readBytes; | ||
bytes = bytes - readBytes; | ||
if (bytes < 1) { | ||
sftp.close(handle, function (err) { | ||
@@ -89,7 +95,10 @@ conn.end(); | ||
resolve(buffer); | ||
return buffer; | ||
return; | ||
} | ||
}) | ||
} else { | ||
sftp.read(handle, buffer, position, bytes, position, cb) | ||
} | ||
}) | ||
} | ||
sftp.read(handle, buffer, 0, bytes, 0, cb) | ||
}) | ||
@@ -96,0 +105,0 @@ }) |
{ | ||
"name": "sftp-promises", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "SFTP Promise wrapper for ssh2 SFTP commands", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -32,2 +32,3 @@ var fs = require('fs'); | ||
it('tranfer buffer to file', function *() { | ||
//this.timeout(0) // enable for testing with large files | ||
var val = yield sftp.putBuffer(buffer, '/tmp/test.dat'); | ||
@@ -37,2 +38,3 @@ val.should.be.true; | ||
it('tranfer file to buffer', function *() { | ||
//this.timeout(0) // enable for testing with large files | ||
var rbuffer = yield sftp.getBuffer('/tmp/test.dat'); | ||
@@ -45,2 +47,3 @@ rbuffer.equals(buffer).should.be.true; | ||
it('should transfer local file to remote', function *() { | ||
this.timeout(0) | ||
var val = yield sftp.put('test/test.dat', '/tmp/test.dat'); | ||
@@ -50,2 +53,3 @@ val.should.be.true; | ||
it('should transfer remote file locally', function *(){ | ||
this.timeout(0) | ||
var val = yield sftp.get('/tmp/test.dat', '/tmp/transfertest.remove'); | ||
@@ -52,0 +56,0 @@ val.should.be.true; |
Sorry, the diff of this file is not supported yet
38642555
10
302