Skip to content

Commit 35a8edd

Browse files
authored
Merge pull request #209 from SEAPUNK/master
Replace all occurences of Ftp.raw[command] with Ftp.raw(command)
2 parents e26e162 + 797a0dc commit 35a8edd

3 files changed

Lines changed: 36 additions & 36 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ callback, in the form of an object that contains two properties: `code`, which
3636
is the response code of the FTP operation, and `text`, which is the complete
3737
text of the response.
3838

39-
Raw (or native) commands are accessible in the form `Ftp.raw["command"](params, callback)`
39+
Raw (or native) commands are accessible in the form `Ftp.raw(command, params, callback)`
4040

4141
Thus, a command like `QUIT` will be called like this:
4242

4343
```javascript
44-
Ftp.raw.quit(function(err, data) {
44+
Ftp.raw("quit", function(err, data) {
4545
if (err) return console.error(err);
4646

4747
console.log("Bye!");
@@ -51,7 +51,7 @@ Ftp.raw.quit(function(err, data) {
5151
and a command like `MKD` (make directory), which accepts parameters, looks like this:
5252

5353
```javascript
54-
Ftp.raw.mkd("/new_dir", function(err, data) {
54+
Ftp.raw("mkd", "/new_dir", function(err, data) {
5555
if (err) return console.error(err);
5656

5757
console.log(data.text); // Show the FTP response text to the user
@@ -101,7 +101,7 @@ Contains the system identification string for the remote FTP server.
101101

102102
### Methods
103103

104-
#### Ftp.raw(command, callback)
104+
#### Ftp.raw(command, [...args], callback)
105105
With the `raw` method you can send any FTP command to the server. The method accepts a callback
106106
with the signature `err, data`, in which `err` is the error response coming
107107
from the server (usually a 4xx or 5xx error code) and the data is an object

lib/jsftp.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ Ftp.prototype.getFeatures = function(callback) {
297297
}
298298

299299
var self = this;
300-
this.raw.feat(function(err, response) {
300+
this.raw('feat', function(err, response) {
301301
self.features = err ? [] : self._parseFeats(response.text);
302-
self.raw.syst(function(err, res) {
302+
self.raw('syst', function(err, res) {
303303
if (!err && res.code === 215) {
304304
self.system = res.text.toLowerCase();
305305
}
@@ -331,13 +331,13 @@ Ftp.prototype.auth = function(user, pass, callback) {
331331
}
332332

333333
this.authenticating = true;
334-
self.raw.user(user, function(err, res) {
334+
self.raw('user', user, function(err, res) {
335335
if (err || [230, 331, 332].indexOf(res.code) === -1) {
336336
self.authenticating = false;
337337
callback(err);
338338
return;
339339
}
340-
self.raw.pass(pass, function(err, res) {
340+
self.raw('pass', pass, function(err, res) {
341341
self.authenticating = false;
342342

343343
if (err) {
@@ -346,11 +346,11 @@ Ftp.prototype.auth = function(user, pass, callback) {
346346
self.authenticated = true;
347347
self.user = user;
348348
self.pass = pass;
349-
self.raw.type('I', function() {
349+
self.raw('type', 'I', function() {
350350
callback(undefined, res);
351351
});
352352
} else if (res.code === 332) {
353-
self.raw.acct(''); // ACCT not really supported
353+
self.raw('acct', ''); // ACCT not really supported
354354
}
355355
});
356356
});
@@ -363,7 +363,7 @@ Ftp.prototype.setType = function(type, callback) {
363363
}
364364

365365
var self = this;
366-
this.raw.type(type, function(err, data) {
366+
this.raw('type', type, function(err, data) {
367367
if (!err) {
368368
self.type = type;
369369
}
@@ -715,7 +715,7 @@ Ftp.prototype.ls = function(filePath, callback) {
715715
this.list(filePath, entriesToList);
716716
} else {
717717
var self = this;
718-
this.raw.stat(filePath, function(err, data) {
718+
this.raw('stat', filePath, function(err, data) {
719719
// We might be connected to a server that doesn't support the
720720
// 'STAT' command, which is set as default. We use 'LIST' instead,
721721
// and we set the variable `useList` to true, to avoid extra round
@@ -737,11 +737,11 @@ Ftp.prototype.ls = function(filePath, callback) {
737737

738738
Ftp.prototype.rename = function(from, to, callback) {
739739
var self = this;
740-
this.raw.rnfr(from, function(err) {
740+
this.raw('rnfr', from, function(err) {
741741
if (err) {
742742
return callback(err);
743743
}
744-
self.raw.rnto(to, callback);
744+
self.raw('rnto', to, callback);
745745
});
746746
};
747747

@@ -751,7 +751,7 @@ Ftp.prototype.keepAlive = function(wait) {
751751
clearInterval(this._keepAliveInterval);
752752
}
753753

754-
this._keepAliveInterval = setInterval(self.raw.noop, wait || IDLE_TIME);
754+
this._keepAliveInterval = setInterval(self.raw.bind(self, 'noop'), wait || IDLE_TIME);
755755
};
756756

757757
Ftp.prototype.destroy = function() {

test/jsftp_test.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ describe('jsftp test suite', function() {
212212
});
213213

214214
it('test print working directory', function(next) {
215-
ftp.raw.pwd(function(err, res) {
215+
ftp.raw('pwd', function(err, res) {
216216
assert(!err, err);
217217

218218
var code = parseInt(res.code, 10);
@@ -223,13 +223,13 @@ describe('jsftp test suite', function() {
223223
});
224224

225225
it('test switch CWD', function(next) {
226-
ftp.raw.cwd(remoteCWD, function(err, res) {
226+
ftp.raw('cwd', remoteCWD, function(err, res) {
227227
assert.ok(!err, err);
228228

229229
var code = parseInt(res.code, 10);
230230
assert.ok(code === 200 || code === 250, 'CWD command was not successful');
231231

232-
ftp.raw.pwd(function(err, res) {
232+
ftp.raw('pwd', function(err, res) {
233233
assert.ok(!err, err);
234234

235235
var code = parseInt(res.code, 10);
@@ -241,7 +241,7 @@ describe('jsftp test suite', function() {
241241
});
242242

243243
it('test switch to unexistent CWD', function(next) {
244-
ftp.raw.cwd('/unexistentDir/', function(err, res) {
244+
ftp.raw('cwd', '/unexistentDir/', function(err, res) {
245245
var code = parseInt(res.code, 10);
246246
assert.ok(!!err);
247247
assert.equal(code, 550, 'A (wrong) CWD command was successful. It should have failed');
@@ -250,7 +250,7 @@ describe('jsftp test suite', function() {
250250
});
251251

252252
it('test switch to unexistent CWD contains special string', function (next) {
253-
ftp.raw.cwd('/unexistentDir/user', function (err, res) {
253+
ftp.raw('cwd', '/unexistentDir/user', function (err, res) {
254254
var code = parseInt(res.code, 10);
255255
assert.equal(code, 550);
256256
next();
@@ -275,11 +275,11 @@ describe('jsftp test suite', function() {
275275
});
276276

277277
it('test ftp node stat', function(next) {
278-
ftp.raw.pwd(function(err, res) {
278+
ftp.raw('pwd', function(err, res) {
279279
assert.ok(!err);
280280
var parent = new RegExp('.*"(.*)".*').exec(res.text)[1];
281281
var path = Path.resolve(parent + '/' + remoteCWD);
282-
ftp.raw.stat(path, function(err, res) {
282+
ftp.raw('stat', path, function(err, res) {
283283
assert.ok(!err, res);
284284
assert.ok(res);
285285

@@ -291,11 +291,11 @@ describe('jsftp test suite', function() {
291291

292292
it('test create and delete a directory', function(next) {
293293
var newDir = remoteCWD + '/ftp_test_dir';
294-
ftp.raw.mkd(newDir, function(err, res) {
294+
ftp.raw('mkd', newDir, function(err, res) {
295295
assert.ok(!err);
296296
assert.equal(res.code, 257);
297297

298-
ftp.raw.rmd(newDir, function(err, res) {
298+
ftp.raw('rmd', newDir, function(err, res) {
299299
assert.ok(!err);
300300
next();
301301
});
@@ -304,11 +304,11 @@ describe('jsftp test suite', function() {
304304

305305
it('test create and delete a directory containing a space', function(next) {
306306
var newDir = remoteCWD + '/ftp test dür';
307-
ftp.raw.mkd(newDir, function(err, res) {
307+
ftp.raw('mkd', newDir, function(err, res) {
308308
assert.ok(!err);
309309
assert.equal(res.code, 257);
310310

311-
ftp.raw.rmd(newDir, function(err, res) {
311+
ftp.raw('rmd', newDir, function(err, res) {
312312
assert.ok(!err);
313313
next();
314314
});
@@ -326,7 +326,7 @@ describe('jsftp test suite', function() {
326326
assert.equal(buffer.length,
327327
Fs.statSync(Path.join(process.cwd(), 'test/jsftp_test.js')).size);
328328

329-
ftp.raw.dele(filePath, function(err, data) {
329+
ftp.raw('dele', filePath, function(err, data) {
330330
assert.ok(!err);
331331
next();
332332
});
@@ -348,7 +348,7 @@ describe('jsftp test suite', function() {
348348
assert.equal(data.action, 'put');
349349
assert.ok(typeof data.transferred, 'number');
350350

351-
ftp.raw.dele(filePath, function(err, data) {
351+
ftp.raw('dele', filePath, function(err, data) {
352352
assert.ok(!err);
353353
next();
354354
});
@@ -377,7 +377,7 @@ describe('jsftp test suite', function() {
377377
var originalFileSize = Fs.statSync(__filename).size;
378378
assert.equal(uploadedFileSize, originalFileSize);
379379

380-
ftp.raw.dele(filePath, function(err, data) {
380+
ftp.raw('dele', filePath, function(err, data) {
381381
assert.ok(!err);
382382
next();
383383
});
@@ -398,7 +398,7 @@ describe('jsftp test suite', function() {
398398

399399
assert.equal(buffer.length, Fs.statSync(__filename).size);
400400

401-
ftp.raw.dele(to, function(err, data) {
401+
ftp.raw('dele', to, function(err, data) {
402402
assert.ok(!err);
403403
next();
404404
});
@@ -475,7 +475,7 @@ describe('jsftp test suite', function() {
475475
socket.on('close', function() {
476476
assert.equal(buffer.length, counter);
477477

478-
ftp.raw.dele(remotePath, function(err, data) {
478+
ftp.raw('dele', remotePath, function(err, data) {
479479
assert.ok(!err);
480480
next();
481481
});
@@ -497,7 +497,7 @@ describe('jsftp test suite', function() {
497497
}, function(err, res) {
498498
assert.ok(!err, err);
499499

500-
ftp.raw.dele(remotePath, function(err, data) {
500+
ftp.raw('dele', remotePath, function(err, data) {
501501
assert.ok(!err);
502502
next();
503503
});
@@ -518,7 +518,7 @@ describe('jsftp test suite', function() {
518518
it('test get fileList array', function(next) {
519519
var file1 = 'testfile.txt';
520520

521-
ftp.raw.cwd(getRemoteFixturesPath(''), function() {
521+
ftp.raw('cwd', getRemoteFixturesPath(''), function() {
522522
ftp.ls('.', function(err, res) {
523523
assert.ok(!err, err);
524524
assert.ok(Array.isArray(res));
@@ -537,13 +537,13 @@ describe('jsftp test suite', function() {
537537

538538
it('test reconnect', function(next) {
539539
this.timeout(10000);
540-
ftp.raw.pwd(function(err, res) {
540+
ftp.raw('pwd', function(err, res) {
541541
if (err) {
542542
throw err;
543543
}
544544

545545
ftp.socket.destroy();
546-
ftp.raw.quit(function(err, res) {
546+
ftp.raw('quit', function(err, res) {
547547
if (err) {
548548
throw err;
549549
}
@@ -763,7 +763,7 @@ describe('jsftp test suite', function() {
763763
it.skip('test listing a folder containing special UTF characters', function(next) {
764764
var dirName = unorm.nfc('_éàèùâêûô_');
765765
var newDir = Path.join(remoteCWD, dirName);
766-
ftp.raw.mkd(newDir, function(err, res) {
766+
ftp.raw('mkd', newDir, function(err, res) {
767767
assert.ok(!err);
768768
assert.equal(res.code, 257);
769769
var list = Fs.readdirSync(Path.join(__dirname, 'fixtures'));

0 commit comments

Comments
 (0)