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

jsftp

Package Overview
Dependencies
Maintainers
1
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.1.6 to 0.2.0

support/streamer/streamer.js

47

jsftp_test.js

@@ -68,2 +68,3 @@ /*

setTimeout(function() {
self.ftp.destroy();
self.ftp = null;

@@ -154,4 +155,4 @@ next();

ftp.list(remoteCWD, function(err, res){
assert.ok(res);
assert.ok(!err);
assert.ok(!err, err);
//assert.ok(res);
next();

@@ -169,4 +170,4 @@ });

ftp.raw.stat(path, function(err, res) {
assert.ok(!err);
assert.ok(res)
assert.ok(!err, res);
assert.ok(res);

@@ -198,2 +199,20 @@ assert.ok(res.code === 211 || res.code === 212 || res.code === 213);

"test create and delete a directory containing a space": function(next) {
var self = this;
var newDir = remoteCWD + "/ftp test dür";
var ftp = this.ftp;
ftp.auth(FTPCredentials.user, FTPCredentials.pass, function(err, res) {
ftp.raw.mkd(newDir, function(err, res) {
assert.ok(!err);
assert.ok(res.code === 257);
ftp.raw.rmd(newDir, function(err, res) {
assert.ok(!err);
next();
});
});
});
},
"test create and delete a file": function(next) {

@@ -210,6 +229,4 @@ var self = this;

ftp.raw.stat(filePath, function(err, res) {
ftp.ls(filePath, function(err, res) {
assert.ok(!err);
assert.equal(buffer.length, Fs.statSync(CWD + "/jsftp_test.js").size);

@@ -241,3 +258,3 @@

ftp.rename(from, to, function(err, res) {
ftp.raw.stat(to, function(err, res) {
ftp.ls(to, function(err, res) {
assert.ok(!err);

@@ -337,3 +354,17 @@ assert.equal(buffer.length, Fs.statSync(CWD + "/jsftp_test.js").size);

});
},
"test stat and pasv calls in parallel": function(next) {
var ftp = this.ftp;
ftp.ls("/", handler);
ftp.ls("/", handler);
var count = 0;
function handler(err, res) {
assert.ok(err== null);
if (++count == 2)
next();
}
}
};

@@ -340,0 +371,0 @@

93

jsftp.js

@@ -71,2 +71,7 @@ /*

this.options = cfg;
// This variable will be true if the server doesn't support the `stat`
// command. Since listing a directory or retrieving file properties is
// quite a common operation, it is more efficient to avoid the round-trip
// to the server.
this.useList = false;

@@ -123,4 +128,2 @@ if (cfg) {

command = command.toLowerCase();
function send() {

@@ -208,5 +211,13 @@ cmd([command, callback]);

// We ignore FTP marks for now. They don't convey useful
// information. A more elegant solution should be found int he
// information. A more elegant solution should be found in the
// future.
return !isMark(x.code);
var mark = isMark(x.code);
/*
if (mark) {
self.cmdListeners.forEach(function(listener) {
listener(null, x);
});
}
*/
return !mark;
}, self.serverResponse(input)), S.append(S.list(null), cmds));

@@ -317,9 +328,9 @@

var self = this;
var ftpResponse = action[0];
var command = action[1];
var cleanCmd = this._sanitize(command[0]);
var callback = command[1];
this.cmdListeners.forEach(function(listener) {
listener(cleanCmd, ftpResponse);
self.cmdListeners.forEach(function(listener) {
listener(self._sanitize(command[0]), ftpResponse);
});

@@ -332,3 +343,3 @@

var hasFailed = ftpResponse && ftpResponse.code > 399;
callback(hasFailed && ftpResponse.text, ftpResponse);
callback(hasFailed && (ftpResponse.text || "Unknown FTP error."), ftpResponse);
}

@@ -364,4 +375,4 @@ };

var _cmd = cmd.slice(0, 5).toUpperCase();
if (_cmd === "PASS ")
var _cmd = cmd.slice(0, 5);
if (_cmd === "pass ")
cmd = _cmd + Array(cmd.length - 5).join("*");

@@ -418,4 +429,14 @@

*/
this.pendingRequests = [];
this.auth = function(user, pass, callback) {
var self = this;
this.pendingRequests.push(callback);
function notifyAll(err, res) {
var cb;
while (cb = self.pendingRequests.shift())
cb(err, res);
}
if (this.authenticating)

@@ -443,3 +464,3 @@ return;

});
callback(null, res);
notifyAll(null, res);
}

@@ -450,3 +471,3 @@ else if (res.code === 332) {

else {
callback(new Error("Login not accepted"));
notifyAll(new Error("Login not accepted"));
}

@@ -456,3 +477,3 @@ });

self.authenticating = false;
callback(new Error("Login not accepted"));
notifyAll(new Error("Login not accepted"));
}

@@ -559,6 +580,7 @@ });

// We make sure that we close the socket AFTER the 'stor'
// command has been sent to the server.
// This would actually work without the setTimeout because FTP
// actually buffers anything written in the socket before doing
// the STOR. But we won't go around trusting other FTP servers.
setTimeout(function() {
socket.end(buffer);
socket.writable && socket.end(buffer);
}, 100);

@@ -597,16 +619,25 @@ }

this.ls = function(filePath, callback) {
var self = this;
this.raw.stat(filePath, function(err, data) {
// We might be connected to a server that doesn't support the
// 'STAT' command. We use 'LIST' instead.
if ((err && data.code === 502) ||
(self.system && self.system.indexOf("hummingbird") > -1)) {
self.list(filePath, function(err, data) {
if (this.useList) {
this.list(filePath, entriesToList);
}
else {
var self = this;
this.raw.stat(filePath, function(err, data) {
// We might be connected to a server that doesn't support the
// 'STAT' command, which is set as default. We use 'LIST' instead,
// and we set the variable `useList` to true, to avoid extra round
// trips to the server to check.
if ((err && (data.code === 502 || data.code === 500)) ||
// Not sure if the "hummingbird" system check ^^^ his still
// necessary. If they support any standards, the 500 error
// should have us covered. Let's leave it for now.
(self.system && self.system.indexOf("hummingbird") > -1)) {
self.useList = true;
self.list(filePath, entriesToList);
}
else {
entriesToList(err, data);
});
}
else {
entriesToList(err, data);
}
});
}
});
}

@@ -617,2 +648,5 @@ function entriesToList(err, entries) {

if (!entries)
return callback(null, []);
callback(null,

@@ -650,2 +684,1 @@ (entries.text || entries)

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

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

# Changes #
## 0.2.0 / 2011-09-01 ##
- Splitting library into two core and experimental modules.
- Created clojure style aliases for 'head': 'first', 'pick' and 'tail':
'rest'.
- Exposing experimental `normilize` and `tree` APIs via
'streamer/experimental' module.
## 0.1.1 / 2011-08-20 ##
- Adding implementation of `stack`.
- Adding implementation of `join`.
- Some internal implementation simplifications.
## 0.1.0 / 2011-08-20 ##
- Breaking API by changing argument order in filter / map / reduce functions.
This style is more friendly when writing code in functional style. So that
high order functions can be defined by currying.
`var odds = map.bind(null, function($) { return !($%2) })`
- Adding `take` function that is similar to `filter`, but resulting stream
contains only first `n` elements that were not filtered out.
## 0.0.4 / 2011-06-27 ##

@@ -27,0 +4,0 @@

{
"name": "streamer",
"id": "streamer",
"version": "0.2.0",
"version": "0.0.4",
"description": "Asynchronously recursive, pure function <3 via lazy streams.",

@@ -20,3 +20,6 @@ "keywords": [ "stream", "functional", "spaghetti", "lazy", "iteration", "async" ],

},
"main": "./core.js",
"main": "./streamer.js",
"engines": {
"node": ">=0.4.0"
},
"scripts": {

@@ -23,0 +26,0 @@ "test": "node tests/test-streamer.js"

@@ -266,6 +266,6 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

function map(lambda, source) {
function map(source, mapper) {
return function stream(next, stop) {
source(function onElement(element) {
next(lambda(element))
next(mapper(element))
}, stop)

@@ -276,3 +276,3 @@ }

// Let's try to map numbers into doubled values:
print(map(function(x) { return x * 2 }, list(1, 2, 3)))
print(map(list(1, 2, 3), function(x) { return x * 2 }))
//

@@ -290,3 +290,3 @@ // >>>

var join = require("path").join
function paths(path) { return map(join.bind(null, path), ls(path)) }
function paths(path) { return map(ls(path), join.bind(null, path)) }

@@ -307,6 +307,6 @@ // Test drive:

// and returns the steam of elements for which the filterer returned true.
function filter(lambda, source) {
function filter(source, filterer) {
return function stream(next, stop) {
source(function onElement(element) {
if (lambda(element)) next(element)
if (filterer(element)) next(element)
}, stop)

@@ -316,3 +316,3 @@ }

// Simple example for filtering out odd numbers from a number stream.
print(filter(function(x) { return x % 2 }, list(1, 2, 3, 4)))
print(filter(list(1, 2, 3, 4), function(x) { return x % 2 }))
//

@@ -329,5 +329,5 @@ // >>>

function dirs(paths) {
var stats = map(stat, paths)
var dirStats = filter(function(stat) { return stat.isDirectory() }, stats)
return map(function(stat) { return stat.path }, dirStats)
var stats = map(paths, stat)
var dirStats = filter(stats, function(stat) { return stat.isDirectory() })
return map(dirStats, function(stat) { return stat.path })
}

@@ -370,4 +370,4 @@

var stats = merge(map(paths, stat))
var dirStats = filter(function(stat) { return stat.isDirectory() }, stats)
return map(function(stat) { return stat.path }, dirStats)
var dirStats = filter(stats, function(stat) { return stat.isDirectory() })
return map(dirStats, function(stat) { return stat.path })
}

@@ -388,3 +388,3 @@

var entries = paths(path)
var nested = merge(map(lstree, dirs(entries)))
var nested = merge(map(dirs(entries), lstree))
return merge(list(entries, nested))

@@ -410,11 +410,11 @@ }

function paths(path) { return map(join.bind(null, path), ls(path)) }
function paths(path) { return map(ls(path), join.bind(null, path)) }
function dirs(paths) {
var stats = map(stat, paths)
var dirStats = filter(function(stat) { return stat.isDirectory() }, stats)
return map(function(stat) { return stat.path }, dirStats)
var stats = map(paths, stat)
var dirStats = filter(stats, function(stat) { return stat.isDirectory() })
return map(dirStats, function(stat) { return stat.path })
}
function lstree(path) {
var entries = paths(path)
var nested = merge(map(lstree, dirs(entries)))
var nested = merge(map(dirs(entries), lstree))
return merge(list(entries, nested))

@@ -421,0 +421,0 @@ }

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../core.js'),
var streamer = require('../streamer.js'),
append = streamer.append, list = streamer.list

@@ -114,2 +114,2 @@ var test = require('./utils.js').test

});
})

@@ -6,3 +6,3 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {

@@ -17,3 +17,3 @@ 'use strict';

}
var list = require('../core.js').list
var list = require('../streamer.js').list

@@ -49,2 +49,3 @@ function test(assert, expected) {

});
})

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../core.js'),
var streamer = require('../streamer.js'),
cache = streamer.cache, list = streamer.list

@@ -102,4 +102,5 @@ var utils = require('./utils.js'),

if (module == require.main)
require('test').run(exports)
require('test').run(exports);
});
})

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../core.js'),
var streamer = require('../streamer.js'),
filter = streamer.filter, list = streamer.list

@@ -17,5 +17,5 @@ var test = require('./utils.js').test

var empty = list()
var mapped = filter(function onEach(element) {
var mapped = filter(empty, function onEach(element) {
assert.fail('filterer was executed')
}, empty)
})
test(assert, done, mapped, [])

@@ -26,5 +26,5 @@ }

var numbers = list(1, 2, 3, 4)
var evens = filter(function onElement(number) {
var evens = filter(numbers, function onElement(number) {
return !(number % 2)
}, numbers)
})
test(assert, done, evens, [2, 4])

@@ -41,3 +41,3 @@ }

}
var odds = filter(function(number) { return number % 2 }, stream)
var odds = filter(stream, function(number) { return number % 2 })
test(assert, done, odds, [ 5, 3, 1 ])

@@ -54,3 +54,3 @@ }

}
var filtered = filter(function(number) { return number % 2 }, stream)
var filtered = filter(stream, function(number) { return number % 2 })
var expected = [ 3, 1 ]

@@ -71,3 +71,3 @@ var actual = []

var stops = []
var filtered = filter(function(x) { called++; return x % 2 }, stream)
var filtered = filter(stream, function(x) { called++; return x % 2 })

@@ -90,2 +90,2 @@ filtered(function next(element) {

});
})

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../core.js'),
var streamer = require('../streamer.js'),
head = streamer.head, list = streamer.list

@@ -72,4 +72,4 @@ var test = require('./utils.js').test

if (module == require.main)
require('test').run(exports)
require('test').run(exports);
});
})

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var hub = require('../core.js').hub
var hub = require('../streamer.js').hub
var utils = require('./utils.js'),

@@ -117,4 +117,5 @@ test = utils.test, pipe = utils.pipe

if (module == require.main)
require('test').run(exports)
require('test').run(exports);
});
})

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var list = require('../core.js').list
var list = require('../streamer.js').list
var test = require('./utils.js').test

@@ -42,4 +42,5 @@

if (module == require.main)
require('test').run(exports)
require('test').run(exports);
});
})

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../core.js'),
var streamer = require('../streamer.js'),
map = streamer.map, list = streamer.list

@@ -17,5 +17,5 @@ var test = require('./utils.js').test

var empty = list()
var mapped = map(function onEach(element) {
var mapped = map(empty, function onEach(element) {
assert.fail('mapper was executed')
}, empty)
})
test(assert, done, mapped, [])

@@ -26,3 +26,3 @@ }

var numbers = list(1, 2, 3, 4)
var doubled = map(function onElement(number) { return number * 2 }, numbers)
var doubled = map(numbers, function onElement(number) { return number * 2 })
test(assert, done, doubled, [2, 4, 6, 8])

@@ -39,3 +39,3 @@ }

}
var mapped = map(function(x) { return x + 1 }, stream)
var mapped = map(stream, function(x) { return x + 1 })
test(assert, done, mapped, [ 6, 5, 4, 3, 2 ])

@@ -52,3 +52,3 @@ }

}
var mapped = map(function(x) { return x * x }, stream)
var mapped = map(stream, function(x) { return x * x })
var expected = [ 9, 4, 1]

@@ -69,3 +69,3 @@ var actual = []

var stops = []
var mapped = map(function(x) { called++; return x * x }, stream)
var mapped = map(stream, function(x) { called++; return x * x })

@@ -85,4 +85,4 @@ mapped(function next(element) {

if (module == require.main)
require('test').run(exports)
require('test').run(exports);
});
})

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../core.js'),
var streamer = require('../streamer.js'),
merge = streamer.merge, list = streamer.list

@@ -114,4 +114,4 @@ var test = require('./utils.js').test

if (module == require.main)
require('test').run(exports)
require('test').run(exports);
});
})

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../core.js'),
var streamer = require('../streamer.js'),
reduce = streamer.reduce, list = streamer.list

@@ -17,5 +17,5 @@ var test = require('./utils.js').test

var empty = list()
var reduced = reduce(function onEach(element) {
var reduced = reduce(empty, function onEach(element) {
assert.fail('reducer was called on empty list')
}, empty, null)
}, null)
test(assert, done, reduced, [ null ])

@@ -26,5 +26,5 @@ }

var numbers = list(1, 2, 3, 4)
var sum = reduce(function onElement(previous, current) {
var sum = reduce(numbers, function onElement(previous, current) {
return (previous || 0) + current
}, numbers)
})
test(assert, done, sum, [ 10 ])

@@ -42,5 +42,5 @@ }

}
var sum = reduce(function(previous, current) {
var sum = reduce(stream, function(previous, current) {
return previous + current
}, stream, 3)
}, 3)
test(assert, done, sum, [ 18 ])

@@ -58,5 +58,5 @@ }

}
var sum = reduce(function(x, y) { return x + y }, stream)
var sum = reduce(stream, function(x, y) { return x + y })
sum(function next(x) {
assert.fail('should not yield value if stream failed')
assert.fail('should not yield value if stream failed');
}, function stop(error) {

@@ -69,4 +69,4 @@ assert.equal(error.message, 'Boom!', 'error propagated to reduced stream')

if (module == require.main)
require('test').run(exports)
require('test').run(exports);
});
})

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../core.js'),
var streamer = require('../streamer.js'),
tail = streamer.tail, list = streamer.list

@@ -77,4 +77,4 @@ var test = require('./utils.js').test

if (module == require.main)
require('test').run(exports)
require('test').run(exports);
});
})

@@ -6,24 +6,22 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
exports['test list'] = require('./list')
exports['test map'] = require('./map')
exports['test filter'] = require('./filter')
exports['test reduce'] = require('./reduce')
exports['test zip'] = require('./zip')
exports['test head'] = require('./head')
exports['test tail'] = require('./tail')
exports['test append'] = require('./append')
exports['test merge'] = require('./merge')
exports['test hub'] = require('./hub')
exports['test cache'] = require('./cache')
exports['test stack'] = require('./stack')
exports['test join'] = require('./join')
exports['test list'] = require('./list.js')
exports['test map'] = require('./map.js')
exports['test filter'] = require('./filter.js')
exports['test reduce'] = require('./reduce.js')
exports['test zip'] = require('./zip.js')
exports['test head'] = require('./head.js')
exports['test tail'] = require('./tail.js')
exports['test append'] = require('./append.js')
exports['test merge'] = require('./merge.js')
exports['test hub'] = require('./hub.js')
exports['test cache'] = require('./cache.js')
if (module == require.main)
require('test').run(exports)
require('test').run(exports);
});
})

@@ -6,3 +6,3 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {

@@ -42,2 +42,2 @@ 'use strict';

});
})

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../core.js'),
var streamer = require('../streamer.js'),
zip = streamer.zip, list = streamer.list

@@ -111,4 +111,4 @@ var test = require('./utils.js').test

if (module == require.main)
require('test').run(exports)
require('test').run(exports);
});
})
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