node-sftp-server
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -47,3 +47,2 @@ "use strict"; | ||
_this.done = true; | ||
console.warn("Going to invoke " + symbol + " on behalf of req: " + _this.req + ". value: " + ssh2.SFTP_STATUS_CODE[symbol]); | ||
return _this.sftpStream.status(_this.req, ssh2.SFTP_STATUS_CODE[symbol]); | ||
@@ -76,3 +75,2 @@ }; | ||
this.req = req; | ||
console.warn("Directory entry requested! " + req); | ||
if (!this.done) { | ||
@@ -86,3 +84,2 @@ return this.emit("dir"); | ||
DirectoryEmitter.prototype.file = function(name) { | ||
console.warn("Returning a file: " + name + " for req: " + this.req); | ||
this.stopped = this.sftpStream.name(this.req, { | ||
@@ -119,3 +116,2 @@ filename: name.toString(), | ||
} | ||
console.warn("Accepting callback!!!!!"); | ||
this.ctx.accept(); | ||
@@ -132,9 +128,8 @@ return this.server._session_start_callback = callback; | ||
function SFTPServer() { | ||
function SFTPServer(privateKey) { | ||
this.server = new ssh2.Server({ | ||
privateKey: fs.readFileSync('ssh_host_rsa_key') | ||
privateKey: fs.readFileSync(privateKey || 'ssh_host_rsa_key') | ||
}, (function(_this) { | ||
return function(client, info) { | ||
client.on('authentication', function(ctx) { | ||
console.warn("Authentication!"); | ||
_this.auth_wrapper = new ContextWrapper(ctx, _this); | ||
@@ -144,3 +139,2 @@ return _this.emit("connect", _this.auth_wrapper); | ||
client.on('end', function() { | ||
console.warn("Disconnection!"); | ||
return _this.emit("end"); | ||
@@ -152,3 +146,2 @@ }); | ||
}; | ||
console.warn("Uhm, I guess we authenticated OK?"); | ||
return client.on('session', function(accept, reject) { | ||
@@ -159,3 +152,2 @@ var session; | ||
var sftpStream; | ||
console.log('Client SFTP session?!?!!?!?!?'); | ||
sftpStream = accept(); | ||
@@ -249,7 +241,5 @@ session = new SFTPSession(sftpStream); | ||
return function(event) { | ||
console.warn("Now looking at event: " + event); | ||
return _this.sftpStream.on(event, function() { | ||
var args; | ||
args = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
console.warn("UNIVERSAL EVENT DETECTED: " + event + " - reqid: " + args[0]); | ||
return _this[event].apply(_this, args); | ||
@@ -274,3 +264,2 @@ }); | ||
var callback; | ||
console.warn("REALPATH METHOD CALLED via reqid: " + reqid + " for path: " + path); | ||
if (EventEmitter.listenerCount(this, "realpath")) { | ||
@@ -300,3 +289,3 @@ callback = (function(_this) { | ||
} else { | ||
console.warn("WARNING: No stat function for " + kind + ", all files exist!"); | ||
console.log("WARNING: No stat function for " + kind + ", all files exist!"); | ||
return this.sftpStream.attrs(reqid, { | ||
@@ -324,3 +313,2 @@ filename: path, | ||
var handle; | ||
console.warn("New Listener detected!!!!! FREAK OUT!!!! " + event); | ||
if (event !== "dir") { | ||
@@ -345,3 +333,2 @@ return; | ||
if (((ref = this.handles[handle]) != null ? ref.mode : void 0) !== "OPENDIR") { | ||
console.warn("handle: " + handle + " is not an open directory!"); | ||
return this.sftpStream.status(reqid, ssh2.SFTP_STATUS_CODE.NO_SUCH_FILE); | ||
@@ -383,3 +370,2 @@ } | ||
handle = _this.fetchhandle(); | ||
console.warn("INTERNAL _read METHOD INVOKED, DELAYED HANDLE IS BEING RETURNED: " + handle); | ||
_this.handles[handle] = { | ||
@@ -402,8 +388,5 @@ mode: "WRITE", | ||
var badchunk, chunk, goodchunk; | ||
console.warn("READ REQUEST FIRED - all we're doing is...asking for reqid: " + reqid + ", offset: " + offset + ", length: " + length); | ||
chunk = this.handles[handle].stream.read(); | ||
if (chunk) { | ||
console.warn("INSTA-CHUNK AVAIL!!!!"); | ||
if ((chunk != null ? chunk.length : void 0) > length) { | ||
console.warn("CHUNK IS TOOOOOOOOOOO BIIIIIIGGGGGGGG - you should split, return one, and 'unshift' the other?"); | ||
badchunk = chunk.slice(length); | ||
@@ -421,6 +404,4 @@ goodchunk = chunk.slice(0, length); | ||
return function() { | ||
console.warn("READABLE FIRED?!"); | ||
chunk = _this.handles[handle].stream.read(); | ||
if ((chunk != null ? chunk.length : void 0) > length) { | ||
console.warn("CHUNK IS TOOOOOOOOOOO BIIIIIIGGGGGGGG - you should split, return one, and 'unshift' the other?"); | ||
badchunk = chunk.slice(length); | ||
@@ -431,3 +412,2 @@ goodchunk = chunk.slice(0, length); | ||
} | ||
console.warn("Read request gave us " + (chunk != null ? chunk.length : void 0) + " bytes!"); | ||
if (chunk) { | ||
@@ -440,3 +420,2 @@ _this.sftpStream.data(reqid, chunk); | ||
} else { | ||
console.warn("RETURNING EMPTY STREAM!"); | ||
_this.sftpStream.data(reqid, new Buffer("")); | ||
@@ -452,3 +431,2 @@ return _this.handles[handle].stream.read(0); | ||
SFTPSession.prototype.WRITE = function(reqid, handle, offset, data) { | ||
console.warn("WRITE DETECTED: handle: " + handle + ", offset: " + offset + ", datalength: " + data.length); | ||
this.handles[handle].stream.push(data); | ||
@@ -463,3 +441,2 @@ return this.sftpStream.status(reqid, ssh2.SFTP_STATUS_CODE.OK); | ||
case "OPENDIR": | ||
console.warn("Closing directory for handle: " + handle); | ||
this.handles[handle].responder.emit("end"); | ||
@@ -472,3 +449,2 @@ delete this.handles[handle]; | ||
case "WRITE": | ||
console.warn("CLOSE-WRITE"); | ||
this.handles[handle].stream.push(null); | ||
@@ -478,4 +454,2 @@ delete this.handles[handle]; | ||
default: | ||
console.warn("Handle: " + handle + " has data:"); | ||
console.dir(this.handles[handle]); | ||
return this.sftpStream.status(reqid, ssh2.SFTP_STATUS_CODE.FAILURE); | ||
@@ -482,0 +456,0 @@ } |
{ | ||
"name": "node-sftp-server", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Node.js SFTP Server bindings to implement your own SFTP Server", | ||
@@ -5,0 +5,0 @@ "main": "node-sftp-server.js", |
@@ -28,6 +28,7 @@ | ||
```js | ||
var myserver=new SFTPServer(); // some params should go there, like keys? | ||
var myserver=new SFTPServer("path_to_private_key_file"); | ||
``` | ||
This returns a new `SFTPServer()` object, which is an EventEmitter. | ||
This returns a new `SFTPServer()` object, which is an EventEmitter. If the private | ||
key is not specified, the constructor will try to use `ssh_host_rsa_key`. | ||
@@ -34,0 +35,0 @@ ### methods |
100
32155
432