fix: improve connection close events and handlers (#123)
* (fix) base: set datasocket to null once destroyed (#119) Ensure new sockets get created when uploading files by setting the datasocket to null after its destroyed * fix(stor): use the close event (#118) The 'end' event is not called when using SSL. Should use the 'close' event * refactor(list): chained promises with less depth (#117) * Update list.js Tidy up of the List function. Makes the intent of the method clearer, as there are less nested promises * refactor(list): chained promises with less depth * refactor: fixup formatting * test: update test file config
This commit is contained in:
@@ -24,20 +24,20 @@ module.exports = {
|
|||||||
return getFileStat(file, _.get(this, 'server.options.file_format', 'ls'));
|
return getFileStat(file, _.get(this, 'server.options.file_format', 'ls'));
|
||||||
};
|
};
|
||||||
|
|
||||||
const fileList = files.map(file => {
|
return Promise.try(() => files.map(file => {
|
||||||
const message = getFileMessage(file);
|
const message = getFileMessage(file);
|
||||||
return {
|
return {
|
||||||
raw: true,
|
raw: true,
|
||||||
message,
|
message,
|
||||||
socket: this.connector.socket
|
socket: this.connector.socket
|
||||||
};
|
};
|
||||||
});
|
}));
|
||||||
return this.reply(150)
|
|
||||||
.then(() => {
|
|
||||||
if (fileList.length) return this.reply({}, ...fileList);
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.then(() => this.reply(226))
|
.tap(() => this.reply(150))
|
||||||
|
.then(fileList => {
|
||||||
|
if (fileList.length) return this.reply({}, ...fileList);
|
||||||
|
})
|
||||||
|
.tap(() => this.reply(226))
|
||||||
.catch(Promise.TimeoutError, err => {
|
.catch(Promise.TimeoutError, err => {
|
||||||
log.error(err);
|
log.error(err);
|
||||||
return this.reply(425, 'No connection established');
|
return this.reply(425, 'No connection established');
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ module.exports = {
|
|||||||
stream.write(data, this.transferType, () => this.connector.socket && this.connector.socket.resume());
|
stream.write(data, this.transferType, () => this.connector.socket && this.connector.socket.resume());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.connector.socket.once('end', () => {
|
this.connector.socket.once('close', () => {
|
||||||
if (stream.listenerCount('close')) stream.emit('close');
|
if (stream.listenerCount('close')) stream.emit('close');
|
||||||
else stream.end();
|
else stream.end();
|
||||||
resolve();
|
resolve();
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class Connector {
|
|||||||
const closeDataSocket = new Promise(resolve => {
|
const closeDataSocket = new Promise(resolve => {
|
||||||
if (this.dataSocket) {
|
if (this.dataSocket) {
|
||||||
this.dataSocket.end().destroy();
|
this.dataSocket.end().destroy();
|
||||||
|
this.dataSocket = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ const FtpServer = require('../src');
|
|||||||
|
|
||||||
const log = bunyan.createLogger({name: 'test'});
|
const log = bunyan.createLogger({name: 'test'});
|
||||||
log.level('trace');
|
log.level('trace');
|
||||||
const server = new FtpServer('ftp://127.0.0.1:8880', {
|
const server = new FtpServer({
|
||||||
|
url: 'ftp://127.0.0.1:8880',
|
||||||
log,
|
log,
|
||||||
pasv_range: 8881,
|
pasv_range: 8881,
|
||||||
greeting: ['Welcome', 'to', 'the', 'jungle!'],
|
greeting: ['Welcome', 'to', 'the', 'jungle!'],
|
||||||
|
|||||||
Reference in New Issue
Block a user