Comparing version 2.1.0 to 2.1.1
@@ -497,2 +497,6 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */ | ||
if (err) { | ||
if (socket) { | ||
// close the socket since it won't be used | ||
socket.destroy(); | ||
} | ||
return callback(err); | ||
@@ -509,2 +513,5 @@ } | ||
// close the socket since it won't be used | ||
socket.destroy(); | ||
return callback(new Error("Unexpected command " + res.text)); | ||
@@ -569,2 +576,6 @@ } | ||
if (err) { | ||
if (socket) { | ||
// close the socket since it won't be used | ||
socket.destroy(); | ||
} | ||
return next(err); | ||
@@ -578,2 +589,6 @@ } | ||
if (err) { | ||
if (socket) { | ||
// close the socket since it won't be used | ||
socket.destroy(); | ||
} | ||
return next(err); | ||
@@ -592,4 +607,9 @@ } | ||
} else { | ||
if (socket) { | ||
// close the socket since it won't be used | ||
socket.destroy(); | ||
} | ||
return next(new Error("Unexpected command " + res.text)); | ||
} | ||
}); | ||
@@ -596,0 +616,0 @@ |
{ | ||
"name": "jsftp", | ||
"id": "jsftp", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "A sane FTP client implementation for NodeJS", | ||
"keywords": ["ftp", "protocol", "files", "server", "client", "async"], | ||
"author": | ||
"Sergi Mansilla <sergi.mansilla@gmail.com> (http://sergimansilla.com)", | ||
"keywords": [ | ||
"ftp", | ||
"protocol", | ||
"files", | ||
"server", | ||
"client", | ||
"async" | ||
], | ||
"author": "Sergi Mansilla <sergi.mansilla@gmail.com> (http://sergimansilla.com)", | ||
"homepage": "https://github.com/sergi/jsftp", | ||
@@ -28,7 +34,7 @@ "repository": { | ||
"ftp-test-server": "0.0.2", | ||
"ftpd": "sstur/nodeftpd#0d299f7", | ||
"ftpd": "github:sstur/nodeftpd#0d299f7", | ||
"istanbul": "^0.3.22", | ||
"mocha": "^4.0.1", | ||
"mocha-istanbul": "0.2.0", | ||
"nyc": "^11.3.0", | ||
"nyc": "^11.4.0", | ||
"rimraf": "^2.6.1", | ||
@@ -35,0 +41,0 @@ "sinon": "^4.1.2" |
207
README.md
@@ -1,6 +0,5 @@ | ||
# jsftp | ||
# jsftp | ||
[![travis][travis-image]][travis-url] | ||
[![npm][npm-image]][npm-url] | ||
[![downloads][downloads-image]][downloads-url] | ||
[![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] | ||
[![downloads][downloads-image]][downloads-url] | ||
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) | ||
@@ -15,7 +14,6 @@ | ||
A client FTP library for NodeJS that focuses on correctness, clarity | ||
and conciseness. It doesn't get in the way and plays nice with streaming APIs. | ||
A client FTP library for NodeJS that focuses on correctness, clarity and | ||
conciseness. It doesn't get in the way and plays nice with streaming APIs. | ||
Starting it up | ||
-------------- | ||
## Starting it up | ||
@@ -43,3 +41,4 @@ ```javascript | ||
Raw (or native) commands are accessible in the form `Ftp.raw(command, params, callback)` | ||
Raw (or native) commands are accessible in the form `Ftp.raw(command, params, | ||
callback)` | ||
@@ -49,38 +48,41 @@ Thus, a command like `QUIT` will be called like this: | ||
```javascript | ||
Ftp.raw("quit", function(err, data) { | ||
if (err) return console.error(err); | ||
Ftp.raw("quit", (err, data) => { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
console.log("Bye!"); | ||
console.log("Bye!"); | ||
}); | ||
``` | ||
and a command like `MKD` (make directory), which accepts parameters, looks like this: | ||
and a command like `MKD` (make directory), which accepts parameters, looks like | ||
this: | ||
```javascript | ||
Ftp.raw("mkd", "/new_dir", function(err, data) { | ||
if (err) return console.error(err); | ||
console.log(data.text); // Show the FTP response text to the user | ||
console.log(data.code); // Show the FTP response code to the user | ||
Ftp.raw("mkd", "/new_dir", (err, data) => { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
console.log(data.text); // Show the FTP response text to the user | ||
console.log(data.code); // Show the FTP response code to the user | ||
}); | ||
``` | ||
API and examples | ||
---------------- | ||
## API and examples | ||
#### new Ftp(options) | ||
- `options` is an object with the following properties: | ||
```javascript | ||
{ | ||
host: 'localhost', // Host name for the current FTP server. | ||
port: 3333, // Port number for the current FTP server (defaults to 21). | ||
user: 'user', // Username | ||
pass: 'pass', // Password | ||
} | ||
``` | ||
* `options` is an object with the following properties: | ||
```javascript | ||
{ | ||
host: 'localhost', // Host name for the current FTP server. | ||
port: 3333, // Port number for the current FTP server (defaults to 21). | ||
user: 'user', // Username | ||
pass: 'pass', // Password | ||
} | ||
``` | ||
Creates a new Ftp instance. | ||
#### Ftp.host | ||
@@ -100,4 +102,4 @@ | ||
Array of feature names for the current FTP server. It is | ||
generated when the user authenticates with the `auth` method. | ||
Array of feature names for the current FTP server. It is generated when the user | ||
authenticates with the `auth` method. | ||
@@ -108,13 +110,15 @@ #### Ftp.system | ||
### Methods | ||
#### Ftp.raw(command, [...args], callback) | ||
With the `raw` method you can send any FTP command to the server. The method accepts 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 string itself. | ||
With the `raw` method you can send any FTP command to the server. The method | ||
accepts 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 | ||
string itself. | ||
#### Ftp.auth(username, password, callback) | ||
Authenticates the user with the given username and password. If null or empty | ||
@@ -126,2 +130,3 @@ values are passed for those, `auth` will use anonymous credentials. `callback` | ||
#### Ftp.ls(filePath, callback) | ||
Lists information about files or directories and yields an array of file objects | ||
@@ -133,4 +138,4 @@ with parsed file properties to the `callback`. You should use this function | ||
```javascript | ||
ftp.ls(".", function(err, res) { | ||
res.forEach(function(file) { | ||
ftp.ls(".", (err, res) => { | ||
res.forEach(file => { | ||
console.log(file.name); | ||
@@ -142,2 +147,3 @@ }); | ||
#### Ftp.list(filePath, callback) | ||
Lists `filePath` contents using a passive connection. Calls callback with a | ||
@@ -147,3 +153,3 @@ string containing the directory contents in long list format. | ||
```javascript | ||
ftp.list(remoteCWD, function(err, res) { | ||
ftp.list(remoteCWD, (err, res) => { | ||
console.log(res); | ||
@@ -159,39 +165,48 @@ // Prints something like | ||
#### Ftp.get(remotePath, callback) | ||
Gives back a paused socket with the file contents ready to be streamed, | ||
or calls the callback with an error if not successful. | ||
Gives back a paused socket with the file contents ready to be streamed, or calls | ||
the callback with an error if not successful. | ||
```javascript | ||
var str = ""; // Will store the contents of the file | ||
ftp.get('remote/path/file.txt', function(err, socket) { | ||
if (err) return; | ||
var str = ""; // Will store the contents of the file | ||
ftp.get("remote/path/file.txt", (err, socket) => { | ||
if (err) { | ||
return; | ||
} | ||
socket.on("data", function(d) { str += d.toString(); }) | ||
socket.on("close", function(hadErr) { | ||
if (hadErr) | ||
console.error('There was an error retrieving the file.'); | ||
}); | ||
socket.resume(); | ||
socket.on("data", d => { | ||
str += d.toString(); | ||
}); | ||
socket.on("close", err => { | ||
if (hadErr) console.error("There was an error retrieving the file."); | ||
}); | ||
socket.resume(); | ||
}); | ||
``` | ||
#### Ftp.get(remotePath, localPath, callback) | ||
Stores the remote file directly in the given local path. | ||
```javascript | ||
ftp.get('remote/file.txt', 'local/file.txt', function(hadErr) { | ||
if (hadErr) | ||
console.error('There was an error retrieving the file.'); | ||
else | ||
console.log('File copied successfully!'); | ||
}); | ||
ftp.get("remote/file.txt", "local/file.txt", err => { | ||
if (hadErr) { | ||
return console.error("There was an error retrieving the file."); | ||
} | ||
console.log("File copied successfully!"); | ||
}); | ||
``` | ||
#### Ftp.put(source, remotePath, callback) | ||
Uploads a file to `filePath`. It accepts a string with the local path for the | ||
file or a `Buffer` as a `source` parameter. | ||
file, a `Buffer`, or a Readable stream as a `source` parameter. | ||
```javascript | ||
ftp.put(buffer, 'path/to/remote/file.txt', function(hadError) { | ||
if (!hadError) | ||
ftp.put(buffer, "path/to/remote/file.txt", err => { | ||
if (!err) { | ||
console.log("File transferred successfully!"); | ||
} | ||
}); | ||
@@ -201,8 +216,10 @@ ``` | ||
#### Ftp.rename(from, to, callback) | ||
Renames a file in the server. `from` and `to` are both filepaths. | ||
```javascript | ||
ftp.rename(from, to, function(err, res) { | ||
if (!err) | ||
ftp.rename(from, to, (err, res) => { | ||
if (!err) { | ||
console.log("Renaming successful!"); | ||
} | ||
}); | ||
@@ -212,10 +229,11 @@ ``` | ||
#### Ftp.keepAlive([wait]) | ||
Refreshes the interval thats keep the server connection active. `wait` is an optional time period (in milliseconds) to wait between intervals. | ||
You can find more usage examples in the [unit tests](https://github.com/sergi/jsftp/blob/master/test/jsftp_test.js). This documentation | ||
will grow as jsftp evolves. | ||
Refreshes the interval thats keep the server connection active. `wait` is an | ||
optional time period (in milliseconds) to wait between intervals. | ||
You can find more usage examples in the | ||
[unit tests](https://github.com/sergi/jsftp/blob/master/test/jsftp_test.js). | ||
This documentation will grow as jsftp evolves. | ||
Debugging | ||
--------- | ||
<!-- ## Debugging | ||
@@ -246,51 +264,44 @@ In order to enable debug mode in a FTP connection, a `debugMode` parameter can | ||
- `response` events: These are response from the FTP server to the user's FTP | ||
* `response` events: These are response from the FTP server to the user's FTP | ||
commands | ||
- `user_command` events: These are commands that the user issues to the | ||
FTP server. | ||
* `user_command` events: These are commands that the user issues to the FTP | ||
server. | ||
- `event:{event name}` events: These are other events mostly related to the server | ||
connection, such as `timeout`, `connect` or `disconnect`. For example, | ||
* `event:{event name}` events: These are other events mostly related to the | ||
server connection, such as `timeout`, `connect` or `disconnect`. For example, | ||
a timeout event will have the name `event:timeout`. | ||
In order to react to print all debug events (for example), we would listen to the | ||
debug messages like this: | ||
In order to react to print all debug events (for example), we would listen to | ||
the debug messages like this: | ||
```javascript | ||
Ftp.on('jsftp_debug', function(eventType, data) { | ||
console.log('DEBUG: ', eventType); | ||
Ftp.on("jsftp_debug", function(eventType, data) { | ||
console.log("DEBUG: ", eventType); | ||
console.log(JSON.stringify(data, null, 2)); | ||
}); | ||
``` | ||
``` --> | ||
Installation | ||
------------ | ||
## Installation | ||
npm install jsftp | ||
Test coverage | ||
------------- | ||
## Tests and Coverage | ||
In order to run coverage reports: | ||
To run tests and coverage reports: | ||
npm install --dev | ||
make coverage | ||
npm test | ||
Current overall coverage rate: | ||
lines......: 95.5% (278 of 291 lines) | ||
functions..: 100% (69 of 69 functions) | ||
... | ||
41 tests passing (6s) | ||
|----------|----------|----------|----------|----------|----------------| | ||
|File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines | | ||
|----------|----------|----------|----------|----------|----------------| | ||
|All files | 88 | 74.87 | 95.45 | 88 | | | ||
| jsftp.js | 88 | 74.87 | 95.45 | 88 |... 693,695,704 | | ||
|----------|----------|----------|----------|----------|----------------| | ||
Tests | ||
----- | ||
## License | ||
To run tests: | ||
npm install --dev | ||
npm test | ||
License | ||
------- | ||
See LICENSE. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
713
295
112079
13