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

jsftp

Package Overview
Dependencies
Maintainers
0
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsftp - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

30

jsftp_test.js

@@ -28,3 +28,3 @@ /*

module.exports = {
timeout: 60000,
timeout: 10000,

@@ -185,2 +185,30 @@ setUp: function(next) {

"test rename a file": function(next) {
var self = this;
var from = CWD + "/file_ftp_test.txt";
var to = CWD + "/file_ftp_test_renamed.txt";
var ftp = this.ftp;
ftp.auth(FTPCredentials.user, FTPCredentials.pass, function(err, res) {
Fs.readFile(CWD + "/jsftp_test.js", "binary", function(err, data) {
var buffer = new Buffer(data, "binary");
ftp.put(from, buffer, function(err, res) {
assert.ok(!err, err);
ftp.rename(from, to, function(err, res) {
ftp.raw.stat(to, function(err, res) {
assert.ok(!err);
assert.equal(buffer.length, Fs.statSync(to).size);
ftp.raw.dele(to, function(err, data) {
assert.ok(!err);
next();
});
});
});
});
});
});
},
"test get a file": function(next) {

@@ -187,0 +215,0 @@ var filePath = CWD + "/jsftp_test.js";

@@ -32,3 +32,15 @@ /*

// This array contains the codes for special commands, such as RETR or STOR,
// which send two responses instead of one. Not a multiline response, but
// literally two.
var SPECIAL_CMDS = [150];
var Ftp = module.exports = function (cfg) {
if (cfg.onError)
this.onError = cfg.onError;
if (cfg.onTimeout)
this.onTimeout = cfg.onTimeout;
// Generate generic methods from parameter names. They can easily be

@@ -95,3 +107,10 @@ // overriden if we need special behavior. They accept any parameters given,

tasks(this.parse.bind(this), function(){});
tasks(this.parse.bind(this), function(err) {
if (err && self.onError)
self.onError(err);
self.destroy();
});
this.cmd = cmd;
};

@@ -104,6 +123,13 @@

socket.setEncoding("utf8");
var self = this;
//var self = this;
socket.setTimeout(TIMEOUT, function() {
if (this.onTimeout)
this.onTimeout(new Error("FTP socket timeout"));
self.destroy();
throw new Error("FTP socket timeout");
}.bind(this));
socket.on("connect", function() {
if (this.onConnect)
this.onConnect();
});

@@ -124,2 +150,3 @@

var currentCode = 0;
var self = this;

@@ -146,2 +173,9 @@ return function stream(next, stop) {

// If the response code belongs to one of the 'special'
// commands (see above), insert a dummy command to pair
// it up properly with its response, and avoid messing
// up the zipped streams.
if (SPECIAL_CMDS.indexOf(code) > -1)
self.cmd(null)
next({ code: code, text: line });

@@ -175,2 +209,5 @@ }

if (!command)
return;
var cmdName, callback;

@@ -375,4 +412,8 @@ if (command) {

self.setPassive(mode, callback, function(socket) {
self.raw.stor(filePath);
socket.end(buffer);
self.raw.stor(filePath, function(err, res) {
if (err)
callback(err);
socket.end(buffer);
});
});

@@ -407,2 +448,12 @@ });

this.rename = function(from, to, callback) {
var raw = this.raw;
raw.rnfr(from, function(err, res) {
if (err)
callback(err);
raw.rnto(to, function(err, res) { callback(err, res) });
});
}
this.keepAlive = function() {

@@ -409,0 +460,0 @@ if (this._keepAliveInterval)

21

lib/ftpPasv.js

@@ -12,4 +12,3 @@ /*

var ftpPasv = module.exports = function(host, port, mode, callback, onConnect) {
this.data = [];
this.mode = mode;
var data = [];

@@ -30,16 +29,18 @@ var socket = this.socket = Net.createConnection(port, host);

var requests = function(source) {
source(function(data) {
self.data.push(data);
source(function(result) {
data.push(result);
}, function(error) {
if (error)
if (error && callback)
callback(error);
if (mode === "I")
callback(null, concat(self.data));
else if(mode === "A")
callback(null, self.data.join("\n"));
if (callback) {
if (mode === "I")
callback(null, concat(data));
else if(mode === "A")
callback(null, data.join("\n"));
}
});
};
var incoming = S.list(requests(input));
S.list(requests(input));
};

@@ -46,0 +47,0 @@

{
"name": "jsftp",
"id": "jsftp",
"version": "0.0.4",
"version": "0.0.5",
"description": "A sane FTP client implementation for NodeJS",

@@ -6,0 +6,0 @@ "keywords": [ "ftp", "streams", "files", "server", "client", "async" ],

@@ -128,2 +128,10 @@ jsftp

### Ftp[FTP_COMMAND]([params], callback)
All the standard FTP commands are available under the `raw` namespace. These
commands might accept parameters or not, but they always accept a callback
with the signature `err, data`, in which `err` is the error response coming
from the server (usually a 4xx or 5xx error code) and the data is an object
that contains two properties: `code` and `text`. `code` is an integer indicating
the response code of the response and `text` is the response stgring itself.
### Ftp.auth(username, password, callback)

@@ -145,2 +153,5 @@ Authenticates the user with the given username and password. If null or empty

### Ftp.rename(from, to, callback)
Renames a file in the server. `from` and `to` are both filepaths.
### Ftp.keepAlive()

@@ -147,0 +158,0 @@ Refreshes the interval thats keep the server connection active. There is no

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