Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sftp-ws

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sftp-ws - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

41

lib/sftp-packet.js

@@ -45,38 +45,13 @@ var SftpPacket = (function () {

var offset = this.offset;
this.writeInt32(value.length);
this.writeInt32(0);
var charLength = value.length;
this.checkSize(value.length);
var length = 0;
for (var i = 0; i < value.length; i++) {
var code = value.charCodeAt(i);
if (code <= 0x7F) {
length += 1;
this.checkSize(1);
this.buffer[this.offset++] = (code | 0);
} else if (code <= 0x7FF) {
length += 2;
this.checkSize(2);
this.buffer[this.offset++] = (code >> 6) | 0x80;
this.buffer[this.offset++] = (code & 0x3F);
} else if (code <= 0xFFFF) {
length += 3;
this.checkSize(3);
this.buffer[this.offset++] = ((code >> 12) & 0x0F) | 0xE0;
this.buffer[this.offset++] = ((code >> 6) & 0x3F) | 0x80;
this.buffer[this.offset++] = (code & 0x3F);
} else if (code <= 0x1FFFFF) {
length += 4;
this.checkSize(4);
this.buffer[this.offset++] = ((code >> 18) & 0x03) | 0xF0;
this.buffer[this.offset++] = ((code >> 12) & 0x0F) | 0xE0;
this.buffer[this.offset++] = ((code >> 6) & 0x3F) | 0x80;
this.buffer[this.offset++] = (code & 0x3F);
} else {
length += 1;
this.checkSize(1);
this.buffer[this.offset++] = 0x3F;
}
}
this.buffer._charsWritten = 0;
var bytesWritten = this.buffer.write(value, this.offset, undefined, 'utf-8');
this.offset += bytesWritten;
if (Buffer._charsWritten != charLength)
throw new Error("Not enough space in the buffer");
this.buffer.writeInt32BE(length, offset, true);
this.buffer.writeInt32BE(bytesWritten, offset, true);
};

@@ -83,0 +58,0 @@

3

lib/sftp-server.js

@@ -102,2 +102,5 @@ var packet = require("./sftp-packet");

SftpServer.prototype.end = function () {
if (typeof this.fs === 'undefined')
return;
this.fs.dispose();

@@ -104,0 +107,0 @@ delete this.fs;

@@ -10,2 +10,3 @@ var __extends = this.__extends || function (d, b) {

var path = require("path");
var stream = require("stream");

@@ -55,8 +56,14 @@ var server = require("./sftp-server");

__extends(Client, _super);
function Client(address) {
function Client(address, options) {
var _this = this;
var ws = new WebSocket(address, {
protocol: "sftp"
});
if (typeof options == 'undefined') {
options = {};
}
if (typeof options.protocol == 'undefined') {
options.protocol = 'sftp';
}
var ws = new WebSocket(address, options);
_super.call(this, new WebSocketStream(ws, {}), "");

@@ -90,2 +97,9 @@

var RequestInfo = (function () {
function RequestInfo() {
}
return RequestInfo;
})();
SFTP.RequestInfo = RequestInfo;
var Server = (function () {

@@ -97,2 +111,3 @@ function Server(options) {

var noServer = false;
var verifyClient = null;

@@ -103,5 +118,9 @@ if (typeof options !== 'undefined') {

this._log = options.log;
this._verifyClient = options.verifyClient;
noServer = options.noServer;
serverOptions.handleProtocols = this._handleProtocols;
serverOptions.handleProtocols = this.handleProtocols;
serverOptions.verifyClient = (function (info, callback) {
_this.verifyClient(info, callback);
});

@@ -115,2 +134,3 @@ for (var option in options) {

case "log":
case "verifyClient":
break;

@@ -127,2 +147,4 @@ default:

this._virtualRoot = process.cwd();
} else {
this._virtualRoot = path.resolve(this._virtualRoot);
}

@@ -154,3 +176,29 @@

}
Server.prototype._handleProtocols = function (protocols, callback) {
Server.prototype.verifyClient = function (info, accept) {
this._log.info("Incoming session request from %s", info.req.connection.remoteAddress);
var innerVerify = this._verifyClient;
if (typeof innerVerify == 'function') {
if (innerVerify.length >= 2) {
var outerAccept = function (result) {
if (typeof result == 'object') {
info.req._sftpSessionInfo = result;
accept(true);
} else {
accept(result);
}
};
innerVerify(info, outerAccept);
} else {
var result = innerVerify(info);
accept(result);
}
}
accept(true);
};
Server.prototype.handleProtocols = function (protocols, callback) {
for (var i = 0; i < protocols.length; i++) {

@@ -203,4 +251,13 @@ var protocol = protocols[i];

var close = function (code) {
session.end();
ws.close(code);
try {
session.end();
} catch (error) {
log.error("Error while closing session.", error);
}
try {
ws.close(code);
} catch (error) {
log.error("Error while closing websocket.", error);
}
};

@@ -207,0 +264,0 @@

{
"name": "sftp-ws",
"version": "0.0.1",
"version": "0.1.0",
"description": "SFTP over WebSockets - client and server library",

@@ -5,0 +5,0 @@ "main": "./lib/sftp.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc