diff --git a/src/commands/registration/list.js b/src/commands/registration/list.js index 3ae24d5..a485839 100644 --- a/src/commands/registration/list.js +++ b/src/commands/registration/list.js @@ -24,20 +24,20 @@ module.exports = { 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); return { raw: true, message, 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 => { log.error(err); return this.reply(425, 'No connection established'); diff --git a/src/commands/registration/stor.js b/src/commands/registration/stor.js index b43f36b..7c7ccb5 100644 --- a/src/commands/registration/stor.js +++ b/src/commands/registration/stor.js @@ -37,7 +37,7 @@ module.exports = { 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'); else stream.end(); resolve(); diff --git a/src/connector/base.js b/src/connector/base.js index d259d9e..ebb7f70 100644 --- a/src/connector/base.js +++ b/src/connector/base.js @@ -30,6 +30,7 @@ class Connector { const closeDataSocket = new Promise(resolve => { if (this.dataSocket) { this.dataSocket.end().destroy(); + this.dataSocket = null; } resolve(); diff --git a/test/start.js b/test/start.js index e50d50e..3b91f1a 100644 --- a/test/start.js +++ b/test/start.js @@ -5,7 +5,8 @@ const FtpServer = require('../src'); const log = bunyan.createLogger({name: 'test'}); 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, pasv_range: 8881, greeting: ['Welcome', 'to', 'the', 'jungle!'],