basic-ftp
Advanced tools
Comparing version 1.0.5 to 1.0.6
# Changelog | ||
## 1.0.6 | ||
- Close sockets on timeout. | ||
## 1.0.5 | ||
@@ -4,0 +8,0 @@ |
@@ -48,3 +48,3 @@ "use strict"; | ||
if (this._socket) { | ||
// Don't destroy the existing control socket automatically. | ||
// Don't close the existing control socket automatically. | ||
// The setter might have been called to upgrade an existing connection. | ||
@@ -70,6 +70,3 @@ this._socket.removeAllListeners(); | ||
set dataSocket(socket) { | ||
if (this._dataSocket) { | ||
this._dataSocket.destroy(); | ||
this._dataSocket.removeAllListeners(); | ||
} | ||
this._closeSocket(this._dataSocket); | ||
this._dataSocket = this._setupSocket(socket); | ||
@@ -83,3 +80,3 @@ } | ||
get hasTLS() { | ||
return this._socket && this._socket.getSession !== undefined; | ||
return this._socket && this._socket.encrypted === true; | ||
} | ||
@@ -92,4 +89,4 @@ | ||
send(command) { | ||
const hasPass = command.indexOf("PASS") !== -1; | ||
const message = hasPass ? "> PASS ###" : `> ${command}`; | ||
// Don't log passwords. | ||
const message = command.startsWith("PASS") ? "> PASS ###" : `> ${command}`; | ||
this.log(message); | ||
@@ -146,5 +143,13 @@ this._socket.write(command + "\r\n"); | ||
socket.setTimeout(this._timeoutMillis); | ||
// Reroute any events to the single communication channel with the currently responsible handler. | ||
socket.on("error", error => this._respond({ error })); | ||
socket.on("timeout", () => this._respond({ error: "Timeout" })); | ||
// Reroute any events to the single communication channel with the currently responsible handler. | ||
// In case of an error, the following will happen: | ||
// 1. The current handler should handle the error by at least rejecting the associated task. | ||
// 2. This rejection will then reject the Promise associated with the task. | ||
// 3. This rejected promise will then lead to an exception in the user's application code. | ||
socket.once("error", error => this._respond({ error })); // An error will automatically close a socket. | ||
// Report timeouts as errors. | ||
socket.once("timeout", () => { | ||
socket.destroy(); // A timeout does not automatically close a socket. | ||
this._respond({ error: "Timeout" }); | ||
}); | ||
} | ||
@@ -151,0 +156,0 @@ return socket; |
{ | ||
"name": "basic-ftp", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "FTP/FTPS client library", | ||
@@ -5,0 +5,0 @@ "main": "./lib/ftp", |
61920
695