Socket
Socket
Sign inDemoInstall

ftp

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ftp - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

454

ftp.js
var util = require('util'),
net = require('net'),
EventEmitter = require('events').EventEmitter,
XRegExp = require('./xregexp'),
reXListUnix = XRegExp.cache('^(?<type>[\\-ld])(?<permission>([\\-r][\\-w][\\-xs]){3})\\s+(?<inodes>\\d+)\\s+(?<owner>\\w+)\\s+(?<group>\\w+)\\s+(?<size>\\d+)\\s+(?<timestamp>((?<month1>\\w{3})\\s+(?<date1>\\d{1,2})\\s+(?<hour>\\d{1,2}):(?<minute>\\d{2}))|((?<month2>\\w{3})\\s+(?<date2>\\d{1,2})\\s+(?<year>\\d{4})))\\s+(?<name>.+)$'),
XRegExp = require('./xregexp');
var reXListUnix = XRegExp.cache('^(?<type>[\\-ld])(?<permission>([\\-r][\\-w][\\-xs]){3})\\s+(?<inodes>\\d+)\\s+(?<owner>\\w+)\\s+(?<group>\\w+)\\s+(?<size>\\d+)\\s+(?<timestamp>((?<month1>\\w{3})\\s+(?<date1>\\d{1,2})\\s+(?<hour>\\d{1,2}):(?<minute>\\d{2}))|((?<month2>\\w{3})\\s+(?<date2>\\d{1,2})\\s+(?<year>\\d{4})))\\s+(?<name>.+)$'),
reXListMSDOS = XRegExp.cache('^(?<month>\\d{2})(?:\\-|\\/)(?<date>\\d{2})(?:\\-|\\/)(?<year>\\d{2,4})\\s+(?<hour>\\d{2}):(?<minute>\\d{2})\\s{0,1}(?<ampm>[AaMmPp]{1,2})\\s+(?:(?<size>\\d+)|(?<isdir>\\<DIR\\>))\\s+(?<name>.+)$'),
reXTimeval = XRegExp.cache('^(?<year>\\d{4})(?<month>\\d{2})(?<date>\\d{2})(?<hour>\\d{2})(?<minute>\\d{2})(?<second>\\d+)$'),
reKV = /(.+?)=(.+?);/,
debug = false;
reKV = /(.+?)=(.+?);/;
var MONTHS = {
jan: 1,
feb: 2,
mar: 3,
apr: 4,
may: 5,
jun: 6,
jul: 7,
aug: 8,
sep: 9,
oct: 10,
nov: 11,
dec: 12
};
var FTP = module.exports = function(options) {

@@ -19,2 +34,3 @@ this._socket = undefined;

this._queue = [];
this.debug = false;
this.options = {

@@ -25,9 +41,7 @@ host: 'localhost',

connTimeout: 15000, // in ms
debug: false/*,
active: false*/ // if numerical, is the port number, otherwise should be false
// to indicate use of passive mode
debug: false
};
extend(true, this.options, options);
if (typeof this.options.debug === 'function')
debug = this.options.debug;
this.debug = this.options.debug;
};

@@ -37,8 +51,17 @@ util.inherits(FTP, EventEmitter);

FTP.prototype.connect = function(port, host) {
var self = this, socket = this._socket, curData = '';
this.options.port = port = port || this.options.port;
this.options.host = host = host || this.options.host;
var self = this,
socket = this._socket,
curData = '';
if (typeof port === 'string')
this.options.host = port;
else if (typeof port === 'number')
this.options.port = port;
if (host !== undefined)
this.options.host = host;
this._feat = new Object();
host = this.options.host;
port = this.options.port;
this._feat = {};
if (socket)

@@ -54,13 +77,11 @@ socket.end();

}, this.options.connTimeout);
socket = this._socket = net.createConnection(port, host);
socket.setEncoding('utf8');
socket = this._socket = new net.Socket();
socket.setEncoding('binary');
socket.setTimeout(0);
socket.on('connect', function() {
clearTimeout(connTimeout);
if (debug)
debug('Connected');
self.debug&&self.debug('Connected');
});
socket.on('end', function() {
if (debug)
debug('Disconnected');
self.debug&&self.debug('Disconnected');
if (self._dataSocket)

@@ -86,6 +107,8 @@ self._dataSocket.end();

curData = '';
if (debug) {
for (var i=0,len=resps.length; i<len; ++i)
debug('Response: code = ' + resps[i][0]
+ (resps[i][1] ? '; text = ' + util.inspect(resps[i][1]) : ''));
if (self.debug) {
for (var i=0,len=resps.length; i<len; ++i) {
self.debug('Response: code = ' + resps[i][0]
+ (resps[i][1] ? '; text = ' + util.inspect(resps[i][1])
: ''));
}
}

@@ -113,4 +136,3 @@

}
if (debug)
debug('Features: ' + util.inspect(self._feat));
self.debug&&self.debug('Features: ' + util.inspect(self._feat));
}

@@ -185,2 +207,3 @@ self.emit('connect');

});
socket.connect(port, host);
};

@@ -246,2 +269,8 @@

FTP.prototype.cdup = function(cb) {
if (this._state !== 'authorized')
return false;
return this.send('CDUP', cb);
};
FTP.prototype.get = function(path, cb) {

@@ -256,2 +285,3 @@ if (this._state !== 'authorized')

stream._decoder = undefined;
var r = self.send('RETR', path, function(e) {

@@ -280,2 +310,3 @@ if (e)

stream._decoder = undefined;
var r = self.send('STOR', destpath, cb);

@@ -355,3 +386,3 @@ if (r) {

FTP.prototype.list = function(path, cb) {
FTP.prototype.list = function(path, streaming, cb) {
if (this._state !== 'authorized')

@@ -363,72 +394,47 @@ return false;

path = undefined;
streaming = false;
} else if (typeof path === 'boolean') {
cb = streaming;
streaming = path;
path = undefined;
}
if (typeof streaming === 'function') {
cb = streaming;
streaming = false;
}
var self = this, emitter = new EventEmitter(), parms;
/*if (parms = this._feat['MLST']) {
var type = undefined,
cbTemp = function(e, text) {
if (e) {
if (!type && e.code === 550) { // path was a file not a dir.
type = 'file';
if (!self.send('MLST', path, cbTemp))
return cb(new Error('Connection severed'));
return;
} else if (!type && e.code === 425) {
type = 'pasv';
if (!self._pasvGetLines(emitter, 'MLSD', cbTemp))
return cb(new Error('Connection severed'));
return;
}
if (type === 'dir')
return emitter.emit('error', e);
else
return cb(e);
}
if (type === 'file') {
cb(undefined, emitter);
var lines = text.split(/\r\n|\n/), result;
lines.shift();
lines.pop();
lines.pop();
result = parseMList(lines[0]);
emitter.emit((typeof result === 'string' ? 'raw' : 'entry'), result);
emitter.emit('end');
emitter.emit('success');
} else if (type === 'pasv') {
type = 'dir';
if (path)
r = self.send('MLSD', path, cbTemp);
else
r = self.send('MLSD', cbTemp);
if (r)
cb(undefined, emitter);
else
cb(new Error('Connection severed'));
} else if (type === 'dir')
emitter.emit('success');
};
var self = this,
emitter = new EventEmitter();
this._pasvGetLines(emitter, 'LIST', function(e) {
if (e)
return cb(e);
var cbTemp = function(e) {
if (e)
return emitter.emit('error', e);
emitter.emit('success');
}, r;
if (path)
return this.send('MLSD', path, cbTemp);
r = self.send('LIST', path, cbTemp);
else
return this.send('MLSD', cbTemp);
} else {*/
// Otherwise use the standard way of fetching a listing
this._pasvGetLines(emitter, 'LIST', function(e) {
if (e)
return cb(e);
var cbTemp = function(e) {
if (e)
return emitter.emit('error', e);
emitter.emit('success');
}, r;
if (path)
r = self.send('LIST', path, cbTemp);
else
r = self.send('LIST', cbTemp);
if (r)
r = self.send('LIST', cbTemp);
if (r) {
if (!streaming) {
var entries = [];
emitter.on('entry', function(entry) {
entries.push(entry);
});
emitter.on('raw', function(line) {
entries.push(line);
});
emitter.on('success', function() {
cb(undefined, entries);
});
emitter.on('error', function(err) {
cb(err);
});
} else
cb(undefined, emitter);
else
cb(new Error('Connection severed'));
});
//}
} else
cb(new Error('Connection severed'));
});
};

@@ -450,12 +456,11 @@

return cb(e);
var val = reXTimeval.exec(text), ret;
var val = reXTimeval.exec(text),
ret;
if (!val)
return cb(new Error('Invalid date/time format from server'));
ret = new Object();
ret.year = parseInt(val.year, 10);
ret.month = parseInt(val.month, 10);
ret.date = parseInt(val.date, 10);
ret.hour = parseInt(val.hour, 10);
ret.minute = parseInt(val.minute, 10);
ret.second = parseFloat(val.second, 10);
// seconds can be a float, we'll just truncate this because Date doesn't
// support fractions of a second
var secs = parseInt(val.second, 10);
ret = new Date(val.year + '-' + val.month + '-' + val.date + 'T' + val.hour
+ ':' + val.minute + ':' + secs);
cb(undefined, ret);

@@ -492,4 +497,3 @@ });

+ (this._queue[0].length === 3 ? ' ' + this._queue[0][1] : '');
if (debug)
debug('> ' + fullcmd);
this.debug&&this.debug('> ' + fullcmd);
this._socket.write(fullcmd + '\r\n');

@@ -502,2 +506,3 @@ }

FTP.prototype._pasvGetLines = function(emitter, type, cb) {
var self = this;
return this.send('PASV', function(e, stream) {

@@ -507,3 +512,3 @@ if (e)

var curData = '', lines;
stream.setEncoding('utf8');
stream.setEncoding('binary');
stream.on('data', function(data) {

@@ -522,3 +527,3 @@ curData += data;

}
processDirLines(lines, emitter, type);
processDirLines(lines, emitter, type, self.debug);
}

@@ -540,44 +545,37 @@ });

var self = this,
pasvTimeout = setTimeout(function() {
var r = self.send('ABOR', function(e) {
self._dataSock.end();
self._pasvPort = self._pasvIP = undefined;
if (e)
return self._callCb(e);
self._callCb(new Error('(PASV) Data connection timed out while connecting'));
});
if (!r)
self._callCb(new Error('Connection severed'));
}, this.options.connTimeout);
var self = this;
if (debug)
debug('(PASV) About to attempt data connection to: ' + this._pasvIP
+ ':' + this._pasvPort);
this.debug&&this.debug('(PASV) About to attempt data connection to: '
+ this._pasvIP + ':' + this._pasvPort);
if (!this._dataSock) {
this._dataSock = new net.Socket();
this._dataSock.on('connect', function() {
clearTimeout(pasvTimeout);
if (debug)
debug('(PASV) Data connection successful');
self._callCb(self._dataSock);
var s = this._dataSock = new net.Socket();
s.on('connect', function() {
clearTimeout(s._pasvTimeout);
self.debug&&self.debug('(PASV) Data connection successful');
self._callCb(s);
});
this._dataSock.on('end', function() {
if (debug)
debug('(PASV) Data connection closed');
s.on('end', function() {
self.debug&&self.debug('(PASV) Data connection closed');
});
s.on('close', function(had_err) {
clearTimeout(self._pasvTimeout);
self._pasvPort = self._pasvIP = undefined;
self._dataSock = undefined;
});
this._dataSock.on('close', function() {
clearTimeout(pasvTimeout);
});
this._dataSock.on('error', function(err) {
if (debug)
debug('(PASV) Error: ' + err);
self._pasvPort = self._pasvIP = undefined
s.on('error', function(err) {
self.debug&&self.debug('(PASV) Error: ' + err);
self._callCb(err);
});
}
s._pasvTimeout = setTimeout(function() {
var r = self.send('ABOR', function(e) {
s.destroy();
if (e)
return self._callCb(e);
self._callCb(new Error('(PASV) Data connection timed out while connecting'));
});
if (!r)
self._callCb(new Error('Connection severed'));
}, this.options.connTimeout);
this._dataSock.connect(this._pasvPort, this._pasvIP);
s.connect(this._pasvPort, this._pasvIP);

@@ -607,7 +605,6 @@ return true;

/******************************************************************************/
function processDirLines(lines, emitter, type) {
function processDirLines(lines, emitter, type, debug) {
for (var i=0,result,len=lines.length; i<len; ++i) {
if (lines[i].length) {
if (debug)
debug('(PASV) Got ' + type + ' line: ' + lines[i]);
debug&&debug('(PASV) Got ' + type + ' line: ' + lines[i]);
if (type === 'LIST')

@@ -623,3 +620,3 @@ result = parseList(lines[i]);

function parseResponses(lines) {
var resps = new Array(),
var resps = [],
multiline = '';

@@ -648,3 +645,3 @@ for (var i=0,match,len=lines.length; i<len; ++i) {

if (result && result.length > 0) {
ret = new Object();
ret = {};
if (result.length === 1)

@@ -667,40 +664,48 @@ ret.name = result[0].trim();

function parseList(line) {
var ret, info, thisYear = (new Date()).getFullYear(),
months = {
jan: 1,
feb: 2,
mar: 3,
apr: 4,
may: 5,
jun: 6,
jul: 7,
aug: 8,
sep: 9,
oct: 10,
nov: 11,
dec: 12
};
var ret,
info,
thisYear = (new Date()).getFullYear(),
month,
day,
year,
hour,
mins;
if (ret = reXListUnix.exec(line)) {
info = new Object();
info.type = ret.type;
info.rights = new Object();
info.rights.user = ret.permission.substring(0, 3).replace('-', '');
info.rights.group = ret.permission.substring(3, 6).replace('-', '');
info.rights.other = ret.permission.substring(6, 9).replace('-', '');
info.owner = ret.owner;
info.group = ret.group;
info.size = ret.size;
info.date = new Object();
if (typeof ret.month1 !== 'undefined') {
info.date.month = parseInt(months[ret.month1.toLowerCase()], 10);
info.date.date = parseInt(ret.date1, 10);
info.date.year = thisYear;
info.time = new Object();
info.time.hour = parseInt(ret.hour, 10);
info.time.minute = parseInt(ret.minute, 10);
} else if (typeof ret.month2 !== 'undefined') {
info.date.month = parseInt(months[ret.month2.toLowerCase()], 10);
info.date.date = parseInt(ret.date2, 10);
info.date.year = parseInt(ret.year, 10);
info = {
type: ret.type,
rights: {
user: ret.permission.substring(0, 3).replace('-', ''),
group: ret.permission.substring(3, 6).replace('-', ''),
other: ret.permission.substring(6, 9).replace('-', '')
},
owner: ret.owner,
group: ret.group,
size: ret.size,
date: undefined
};
if (ret.month1 !== undefined) {
month = parseInt(MONTHS[ret.month1.toLowerCase()], 10);
day = parseInt(ret.date1, 10);
year = thisYear;
hour = parseInt(ret.hour, 10);
mins = parseInt(ret.minute, 10);
if (month < 10)
month = '0' + month;
if (day < 10)
day = '0' + day;
if (hour < 10)
hour = '0' + hour;
if (mins < 10)
mins = '0' + mins;
info.date = new Date(year + '-' + month + '-' + day + 'T' + hour + ':' + mins);
} else if (ret.month2 !== undefined) {
month = parseInt(MONTHS[ret.month2.toLowerCase()], 10);
day = parseInt(ret.date2, 10);
year = parseInt(ret.year, 10);
if (month < 10)
month = '0' + month;
if (day < 10)
day = '0' + day;
info.date = new Date(year + '-' + month + '-' + day);
}

@@ -715,17 +720,29 @@ if (ret.type === 'l') {

} else if (ret = reXListMSDOS.exec(line)) {
info = new Object();
info.type = (ret.isdir ? 'd' : '-');
info.size = (ret.isdir ? '0' : ret.size);
info.date = new Object();
info.date.month = parseInt(ret.month, 10);
info.date.date = parseInt(ret.date, 10);
info.date.year = parseInt(ret.year, 10);
info.time = new Object();
info.time.hour = parseInt(ret.hour, 10);
info.time.minute = parseInt(ret.minute, 10);
if (ret.ampm[0].toLowerCase() === 'p' && info.time.hour < 12)
info.time.hour += 12;
else if (ret.ampm[0].toLowerCase() === 'a' && info.time.hour === 12)
info.time.hour = 0;
info.name = ret.name;
info = {
name: ret.name,
type: (ret.isdir ? 'd' : '-'),
size: (ret.isdir ? '0' : ret.size),
date: undefined,
};
month = parseInt(ret.month, 10),
day = parseInt(ret.date, 10),
year = parseInt(ret.year, 10),
hour = parseInt(ret.hour, 10),
mins = parseInt(ret.minute, 10);
if (ret.ampm[0].toLowerCase() === 'p' && hour < 12)
hour += 12;
else if (ret.ampm[0].toLowerCase() === 'a' && hour === 12)
hour = 0;
if (month < 10)
month = '0' + month;
if (day < 10)
day = '0' + day;
if (hour < 10)
hour = '0' + hour;
if (mins < 10)
mins = '0' + mins;
info.date = new Date(year + '-' + month + '-' + day + 'T' + hour + ':' + mins);
ret = info;

@@ -812,54 +829,1 @@ } else

}
// Target API:
//
// var s = require('net').createStream(25, 'smtp.example.com');
// s.on('connect', function() {
// require('starttls')(s, options, function() {
// if (!s.authorized) {
// s.destroy();
// return;
// }
//
// s.end("hello world\n");
// });
// });
function starttls(socket, options, cb) {
var sslcontext = require('crypto').createCredentials(options),
pair = require('tls').createSecurePair(sslcontext, false),
cleartext = _pipe(pair, socket);
pair.on('secure', function() {
var verifyError = pair._ssl.verifyError();
if (verifyError) {
cleartext.authorized = false;
cleartext.authorizationError = verifyError;
} else
cleartext.authorized = true;
if (cb)
cb();
});
cleartext._controlReleased = true;
return cleartext;
};
function _pipe(pair, socket) {
pair.encrypted.pipe(socket);
socket.pipe(pair.encrypted);
pair.fd = socket.fd;
var cleartext = pair.cleartext;
cleartext.socket = socket;
cleartext.encrypted = pair.encrypted;
cleartext.authorized = false;
function onerror(e) {
if (cleartext._controlReleased)
cleartext.emit('error', e);
}
function onclose() {
socket.removeListener('error', onerror);
socket.removeListener('close', onclose);
}
socket.on('error', onerror);
socket.on('close', onclose);
return cleartext;
}
{ "name": "ftp",
"version": "0.1.3",
"version": "0.1.4",
"author": "Brian White <mscdex@mscdex.net>",

@@ -4,0 +4,0 @@ "description": "An FTP client module for node.js",

@@ -22,78 +22,71 @@ Description

var FTPClient = require('./ftp'), util = require('util'), conn;
function formatDate(d) {
return (d.year < 10 ? '0' : '') + d.year + '-' + (d.month < 10 ? '0' : '')
+ d.month + '-' + (d.date < 10 ? '0' : '') + d.date;
```javascript
var FTPClient = require('ftp');
// connect to localhost:21
var conn = new FTPClient();
conn.on('connect', function() {
// authenticate as anonymous
conn.auth(function(e) {
if (e)
throw e;
conn.list(function(e, entries) {
if (e)
throw e;
console.log('<start of directory list>');
for (var i=0,len=entries.length; i<len; ++i) {
if (typeof entries[i] === 'string')
console.log('<raw entry>: ' + entries[i]);
else {
if (entries[i].type === 'l')
entries[i].type = 'LINK';
else if (entries[i].type === '-')
entries[i].type = 'FILE';
else if (entries[i].type === 'd')
entries[i].type = 'DIR';
console.log(' ' + entries[i].type + ' ' + entries[i].size
+ ' ' + entries[i].date + ' ' + entries[i].name);
}
}
conn = new FTPClient({ host: '127.0.0.1' });
conn.on('connect', function() {
conn.auth(function(e) {
if (e)
throw e;
conn.list(function(e, iter) {
if (e)
throw e;
var begin = false;
iter.on('entry', function(entry) {
if (!begin) {
begin = true;
console.log('<start of directory list>');
}
if (entry.type === 'l')
entry.type = 'LINK';
else if (entry.type === '-')
entry.type = 'FILE';
else if (entry.type === 'd')
entry.type = 'DIR.';
console.log(' ' + entry.type + ' ' + entry.size + ' '
+ formatDate(entry.date) + ' ' + entry.name);
});
iter.on('raw', function(s) {
console.log('<raw entry>: ' + s);
});
iter.on('end', function() {
console.log('<end of directory list>');
});
iter.on('error', function(e) {
console.log('ERROR during list(): ' + util.inspect(e));
conn.end();
});
iter.on('success', function() {
conn.end();
});
});
});
});
conn.connect();
console.log('<end of directory list>');
conn.end();
});
});
});
conn.connect();
```
* Download remote file 'foo.txt' and save it to the local file system:
// Assume we have the same connection 'conn' from before and are currently
// authenticated ...
var fs = require('fs');
conn.get('foo.txt', function(e, stream) {
if (e)
throw e;
stream.on('success', function() {
conn.end();
});
stream.on('error', function(e) {
console.log('ERROR during get(): ' + util.inspect(e));
conn.end();
});
stream.pipe(fs.createWriteStream('localfoo.txt'));
});
```javascript
// Assume we have the same connection 'conn' from before and are currently
// authenticated ...
var fs = require('fs');
conn.get('foo.txt', function(e, stream) {
if (e)
throw e;
stream.on('success', function() {
conn.end();
});
stream.on('error', function(e) {
console.log('ERROR during get(): ' + e);
conn.end();
});
stream.pipe(fs.createWriteStream('localfoo.txt'));
});
```
* Upload local file 'foo.txt' to the server:
// Assume we have the same connection 'conn' from before and are currently
// authenticated ...
var fs = require('fs');
conn.put(fs.createReadStream('foo.txt'), 'remotefoo.txt', function(e) {
if (e)
throw e;
conn.end();
});
```javascript
// Assume we have the same connection 'conn' from before and are currently
// authenticated ...
var fs = require('fs');
conn.put(fs.createReadStream('foo.txt'), 'remotefoo.txt', function(e) {
if (e)
throw e;
conn.end();
});
```
API

@@ -109,7 +102,7 @@ ===

* **close**(Boolean:hasError) - Fires when the connection is completely closed (similar to net.Socket's close event). The specified Boolean indicates whether the connection was terminated due to a transmission error or not.
* **close**(<_boolean_>hasError) - Fires when the connection is completely closed (similar to net.Socket's close event). The specified boolean indicates whether the connection was terminated due to a transmission error or not.
* **end**() - Fires when the connection has ended.
* **error**(Error:err) - Fires when an exception/error occurs (similar to net.Socket's error event). The given Error object represents the error raised.
* **error**(<_Error_>err) - Fires when an exception/error occurs (similar to net.Socket's error event). The given Error object represents the error raised.

@@ -122,3 +115,3 @@

**\* Note 2: Methods that return a Boolean success value will immediately return false if the action couldn't be carried out for reasons including: no server connection or the relevant command is not available on that particular server.**
**\* Note 2: Methods that return a boolean success value will immediately return false if the action couldn't be carried out for reasons including: no server connection or the relevant command is not available on that particular server.**

@@ -129,66 +122,62 @@ ### Standard

* **(constructor)**([Object:config]) - Creates and returns a new instance of the FTP module using the specified configuration object. Valid properties of the passed in object are:
* **String:host** - The hostname or IP address of the FTP server. **Default:** "127.0.0.1"
* **Integer:port** - The port of the FTP server. **Default:** 21
* **Function:debug** - Accepts a string and gets called for debug messages **Default:** (no debug output)
* **Integer:connTimeout** - The number of milliseconds to wait for a connection to be established. **Default:** 15000
* **(constructor)**([<_object_>config]) - Creates and returns a new instance of the FTP module using the specified configuration object. Valid properties of the passed in object are:
* <_string_>host - The hostname or IP address of the FTP server. **Default:** "localhost"
* <_integer_>port - The port of the FTP server. **Default:** 21
* <_integer_>connTimeout - The number of milliseconds to wait for a connection to be established. **Default:** 15000
* <_function_>debug - Accepts a string and gets called for debug messages **Default:** (no debug output)
* **connect**([Number:port],[String:host]) - _(void)_ - Attempts to connect to the FTP server. If the port and host are specified here, they override and overwrite those set in the constructor.
* **connect**(<_integer_>port,][<_string_>host]) - _(void)_ - Attempts to connect to the FTP server. If the port and host are specified here, they override and overwrite those set in the constructor.
* **end**() - _(void)_ - Closes the connection to the server.
* **auth**([String:username], [String:password], Function:callback) - _Boolean:success_ - Authenticates with the server (leave out username and password to log in as anonymous). The callback has these parameters: the error (undefined if none).
* **auth**([<_string_>username, <_string_>password,] <_function_>callback) - <_boolean_>success - Authenticates with the server (leave out username and password to log in as anonymous). The callback has these parameters: the error (undefined if none).
* **list**([String:path], Function:callback) - _Boolean:success_ - Retrieves the directory listing of the specified path. If path is not supplied, the current working directory is used. The callback has these parameters: the error (undefined if none) and an EventEmitter. The EventEmitter emits the following events:
* **list**([<_string_>path,] [<_boolean_>streamList,] <_function_>callback) - <_boolean_>success_ - Retrieves the directory listing of the specified path. path defaults to the current working directory. If streamList is set to true, an EventEmitter will be passed to the callback, otherwise an array of objects (format shown below) and raw strings will be passed in to the callback. The callback has these parameters: the error (undefined if none) and a list source. If streaming the list, the following events are emitted on the list source:
* **entry**(Object:entryInfo) - Fires for each file or subdirectory. entryInfo contains the following possible properties:
* **String:name** - The name of the entry.
* **String:type** - A single character denoting the entry type: 'd' for directory, '-' for file, or 'l' for symlink (UNIX only).
* **String:size** - The size of the entry in bytes.
* **Object:date** - The last modified date of the entry.
* **Integer:month** - (1 through 12)
* **Integer:date** - (1 through 31)
* **Integer:year** - (1, 2, or 4-digits)
* **[Object:time]** - The last modified time of the entry.
* **Integer:hour** - (0 through 23)
* **Integer:minute** - (0 through 59)
* **Object:rights** - (UNIX only) - The various permissions for this entry.
* **String:user** - Contains any combination of 'r', 'w', 'x', or an empty string.
* **String:group** - Contains any combination of 'r', 'w', 'x', or an empty string.
* **String:other** - Contains any combination of 'r', 'w', 'x', or an empty string.
* **String:owner** - (UNIX only) - The user name or ID that this entry belongs to.
* **String:group** - (UNIX only) - The group name or ID that this entry belongs to.
* **[String:target]** - (UNIX only) - For symlink entries, this is the symlink's target.
* **entry**(<_object_>entryInfo) - Emitted for each file or subdirectory. entryInfo contains the following possible properties:
* <_string_>name - The name of the entry.
* <_string_>type - A single character denoting the entry type: 'd' for directory, '-' for file, or 'l' for symlink (UNIX only).
* <_string_>size - The size of the entry in bytes.
* <_Date_>date - The last modified date of the entry.
* <_object_>rights - **(*NIX only)** - The various permissions for this entry.
* <_string_>user - An empty string or any combination of 'r', 'w', 'x'.
* <_string_>group - An empty string or any combination of 'r', 'w', 'x'.
* <_string_>other - An empty string or any combination of 'r', 'w', 'x'.
* <_string_>owner - **(*NIX only)** - The user name or ID that this entry belongs to.
* <_string_>group - **(*NIX only)** - The group name or ID that this entry belongs to.
* <_string_>target - **(*NIX only)** - For symlink entries, this is the symlink's target.
* **raw**(String:rawListing) - Fires when a directory listing couldn't be parsed and provides you with the raw directory listing line.
* **raw**(<_string_>rawListing) - Emitted when a directory listing couldn't be parsed and provides you with the raw directory listing from the server.
* **end**() - Fires when the server has finished sending the directory listing, which may or may not be due to error.
* **end**() - Emitted when the server has finished sending the directory listing, which may or may not be due to error.
* **success**() - Fires when the server says it successfully sent the entire directory listing.
* **success**() - Emitted when the server says it successfully sent the entire directory listing.
* **error**(Error:err) - Fires when an error was encountered while obtaining the directory listing.
* **error**(<_Error_>err) - Emitted when an error was encountered while obtaining the directory listing.
* **pwd**(Function:callback) - _Boolean:success_ - Retrieves the current working directory. The callback has these parameters: the error (undefined if none) and a string containing the current working directory.
* **pwd**(<_function_>callback) - <_boolean_>success - Retrieves the current working directory. The callback has these parameters: the error (undefined if none) and a string containing the current working directory.
* **cwd**(String:newPath, Function:callback) - _Boolean:success_ - Changes the current working directory to newPath. The callback has these parameters: the error (undefined if none).
* **cwd**(<_string_>newPath, <_function_>callback) - <_boolean_>success - Changes the current working directory to newPath. The callback has these parameters: the error (undefined if none).
* **get**(String:filename, Function:callback) - _Boolean:success_ - Retrieves a file from the server. The callback has these parameters: the error (undefined if none) and a ReadableStream. The ReadableStream will emit 'success' if the file was successfully transferred.
* **cdup**(<_function_>callback) - <_boolean_>success - Changes the working directory to the parent of the current directory. The callback has these parameters: the error (undefined if none).
* **put**(ReadableStream:inStream, String:filename, Function:callback) - _Boolean:success_ - Sends a file to the server. The callback has these parameters: the error (undefined if none).
* **get**(<_string_>filename, <_function_>callback) - <_boolean_>success - Retrieves a file from the server. The callback has these parameters: the error (undefined if none) and a ReadableStream. The ReadableStream will emit 'success' if the file was successfully transferred.
* **append**(ReadableStream:inStream, String:filename, Function:callback) - _Boolean:success_ - Same as **put**, except if the file already exists, it will be appended to instead of overwritten.
* **put**(<_ReadableStream_>inStream, <_string_>filename, <_function_>callback) - <_boolean_>success - Sends a file to the server. The callback has these parameters: the error (undefined if none).
* **mkdir**(String:dirname, Function:callback) - _Boolean:success_ - Creates a new directory on the server. The callback has these parameters: the error (undefined if none) and a string containing the path of the newly created directory.
* **append**(<_ReadableStream_>inStream, <_string_>filename, <_function_>callback) - <_boolean_>success - Same as **put**, except if the file already exists, it will be appended to instead of overwritten.
* **rmdir**(String:dirname, Function:callback) - _Boolean:success_ - Removes a directory on the server. The callback has these parameters: the error (undefined if none).
* **mkdir**(<_string_>dirname, <_function_>callback) - <_boolean_>success - Creates a new directory on the server. The callback has these parameters: the error (undefined if none) and a string containing the path of the newly created directory.
* **delete**(String:entryName, Function:callback) - _Boolean:success_ - Deletes a file on the server. The callback has these parameters: the error (undefined if none).
* **rmdir**(<_string_>dirname, <_function_>callback) - <_boolean_>success - Removes a directory on the server. The callback has these parameters: the error (undefined if none).
* **rename**(String:oldFilename, String:newFilename, Function:callback) - _Boolean:success_ - Renames a file on the server. The callback has these parameters: the error (undefined if none).
* **delete**(<_string_>entryName, <_function_>callback) - <_boolean_>success - Deletes a file on the server. The callback has these parameters: the error (undefined if none).
* **system**(Function:callback) - _Boolean:success_ - Retrieves information about the server's operating system. The callback has these parameters: the error (undefined if none) and a string containing the text returned by the server.
* **rename**(<_string_>oldFilename, <_string_>newFilename, <_function_>callback) - <_boolean_>success - Renames a file on the server. The callback has these parameters: the error (undefined if none).
* **status**(Function:callback) - _Boolean:success_ - Retrieves human-readable information about the server's status. The callback has these parameters: the error (undefined if none) and a string containing the text returned by the server.
* **system**(<_function_>callback) - <_boolean_>success - Retrieves information about the server's operating system. The callback has these parameters: the error (undefined if none) and a string containing the text returned by the server.
* **status**(<_function_>callback) - <_boolean_>success - Retrieves human-readable information about the server's status. The callback has these parameters: the error (undefined if none) and a string containing the text returned by the server.
### Extended

@@ -198,14 +187,6 @@

* **size**(String:filename, Function:callback) - _Boolean:success_ - Retrieves the size of the specified file. The callback has these parameters: the error (undefined if none) and a string containing the size of the file in bytes.
* **size**(<_string_>filename, <_function_>callback) - <_boolean_>success - Retrieves the size of the specified file. The callback has these parameters: the error (undefined if none) and a string containing the size of the file in bytes.
* **lastMod**(String:filename, Function:callback) - _Boolean:success_ - Retrieves the date and time the specified file was last modified. The callback has these parameters: the error (undefined if none) and an object:
* **lastMod**(<_string_>filename, <_function_>callback) - <_boolean_>success - Retrieves the date and time the specified file was last modified. The callback has these parameters: the error (undefined if none) and a _Date_ instance representing the last modified date.
* **Object:modTime**
* **Integer:month** - (1 through 12)
* **Integer:date** - (1 through 31)
* **Integer:year** - (4-digit)
* **Integer:hour** - (0 through 23)
* **Integer:minute** - (0 through 59)
* **Float:second** - (0 through 60 -- with 60 being used only at a leap second)
* **restart**(String/Integer:byteOffset, Function:callback) - _Boolean:success_ - Sets the file byte offset for the next file transfer action (get/put/append). The callback has these parameters: the error (undefined if none).
* **restart**(<_mixed_>byteOffset, <_function_>callback) - <_boolean_>success - Sets the file byte offset for the next file transfer action (get/put/append). byteOffset can be an _integer_ or _string_. The callback has these parameters: the error (undefined if none).
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