fix(TYPE): correctly set types, only use for data connections
This commit is contained in:
@@ -17,7 +17,7 @@ module.exports = {
|
|||||||
return when.promise((resolve, reject) => {
|
return when.promise((resolve, reject) => {
|
||||||
dataSocket.on('error', err => stream.emit('error', err));
|
dataSocket.on('error', err => stream.emit('error', err));
|
||||||
|
|
||||||
stream.on('data', data => dataSocket.write(data, this.encoding));
|
stream.on('data', data => dataSocket.write(data, this.transferType));
|
||||||
stream.on('end', () => resolve(this.reply(226)));
|
stream.on('end', () => resolve(this.reply(226)));
|
||||||
stream.on('error', err => reject(err));
|
stream.on('error', err => reject(err));
|
||||||
this.reply(150).then(() => dataSocket.resume());
|
this.reply(150).then(() => dataSocket.resume());
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ module.exports = {
|
|||||||
// It is assumed that the `close` handler will call the end() method
|
// It is assumed that the `close` handler will call the end() method
|
||||||
dataSocket.once('end', () => stream.listenerCount('close') ? stream.emit('close') : stream.end());
|
dataSocket.once('end', () => stream.listenerCount('close') ? stream.emit('close') : stream.end());
|
||||||
dataSocket.once('error', err => reject(err));
|
dataSocket.once('error', err => reject(err));
|
||||||
dataSocket.on('data', data => stream.write(data, this.encoding));
|
dataSocket.on('data', data => stream.write(data, this.transferType));
|
||||||
|
|
||||||
this.reply(150).then(() => dataSocket.resume());
|
this.reply(150).then(() => dataSocket.resume());
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
const _ = require('lodash');
|
|
||||||
|
|
||||||
const ENCODING_TYPES = {
|
|
||||||
A: 'utf8',
|
|
||||||
I: 'binary',
|
|
||||||
L: 'binary'
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
directive: 'TYPE',
|
directive: 'TYPE',
|
||||||
handler: function ({command} = {}) {
|
handler: function ({command} = {}) {
|
||||||
const encoding = _.upperCase(command.arg);
|
|
||||||
if (!ENCODING_TYPES.hasOwnProperty(encoding)) return this.reply(501);
|
|
||||||
|
|
||||||
this.encoding = ENCODING_TYPES[encoding];
|
if (/^A[0-9]?$/i.test(command.arg)) {
|
||||||
return this.reply(200);
|
this.transferType = 'ascii';
|
||||||
|
} else if (/^L[0-9]?$/i.test(command.arg) || /^I$/i.test(command.arg)) {
|
||||||
|
this.transferType = 'binary';
|
||||||
|
} else {
|
||||||
|
return this.reply(501);
|
||||||
|
}
|
||||||
|
return this.reply(200, `Switch to "${this.transferType}" transfer mode.`);
|
||||||
},
|
},
|
||||||
syntax: '{{cmd}} <mode>',
|
syntax: '{{cmd}} <mode>',
|
||||||
description: 'Set the transfer mode, binary (I) or utf8 (A)'
|
description: 'Set the transfer mode, binary (I) or ascii (A)',
|
||||||
|
flags: {
|
||||||
|
feat: 'TYPE A,I,L'
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class Active extends Connector {
|
|||||||
return closeExistingServer()
|
return closeExistingServer()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.dataSocket = new Socket();
|
this.dataSocket = new Socket();
|
||||||
this.dataSocket.setEncoding(this.encoding);
|
this.dataSocket.setEncoding(this.connection.transferType);
|
||||||
this.dataSocket.on('error', err => this.server.emit('client-error', {connection: this.connection, context: 'dataSocket', error: err}));
|
this.dataSocket.on('error', err => this.server.emit('client-error', {connection: this.connection, context: 'dataSocket', error: err}));
|
||||||
this.dataSocket.connect({ host, port, family }, () => {
|
this.dataSocket.connect({ host, port, family }, () => {
|
||||||
this.dataSocket.pause();
|
this.dataSocket.pause();
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class Passive extends Connector {
|
|||||||
this.dataSocket = socket;
|
this.dataSocket = socket;
|
||||||
}
|
}
|
||||||
this.dataSocket.connected = true;
|
this.dataSocket.connected = true;
|
||||||
this.dataSocket.setEncoding(this.connection.encoding);
|
this.dataSocket.setEncoding(this.connection.transferType);
|
||||||
this.dataSocket.on('error', err => this.server.emit('client-error', {connection: this.connection, context: 'dataSocket', error: err}));
|
this.dataSocket.on('error', err => this.server.emit('client-error', {connection: this.connection, context: 'dataSocket', error: err}));
|
||||||
this.dataSocket.on('close', () => {
|
this.dataSocket.on('close', () => {
|
||||||
this.log.debug('Passive connection closed');
|
this.log.debug('Passive connection closed');
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ describe(CMD, function () {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
sandbox = sinon.sandbox.create();
|
sandbox = sinon.sandbox.create();
|
||||||
|
|
||||||
mockClient.encoding = null;
|
mockClient.transferType = null;
|
||||||
sandbox.spy(mockClient, 'reply');
|
sandbox.spy(mockClient, 'reply');
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -24,7 +24,7 @@ describe(CMD, function () {
|
|||||||
return cmdFn({ command: { arg: 'A' } })
|
return cmdFn({ command: { arg: 'A' } })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
expect(mockClient.reply.args[0][0]).to.equal(200);
|
expect(mockClient.reply.args[0][0]).to.equal(200);
|
||||||
expect(mockClient.encoding).to.equal('utf8');
|
expect(mockClient.transferType).to.equal('ascii');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ describe(CMD, function () {
|
|||||||
return cmdFn({ command: { arg: 'I' } })
|
return cmdFn({ command: { arg: 'I' } })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
expect(mockClient.reply.args[0][0]).to.equal(200);
|
expect(mockClient.reply.args[0][0]).to.equal(200);
|
||||||
expect(mockClient.encoding).to.equal('binary');
|
expect(mockClient.transferType).to.equal('binary');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ describe(CMD, function () {
|
|||||||
return cmdFn({ command: { arg: 'L' } })
|
return cmdFn({ command: { arg: 'L' } })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
expect(mockClient.reply.args[0][0]).to.equal(200);
|
expect(mockClient.reply.args[0][0]).to.equal(200);
|
||||||
expect(mockClient.encoding).to.equal('binary');
|
expect(mockClient.transferType).to.equal('binary');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ describe(CMD, function () {
|
|||||||
return cmdFn({ command: { arg: 'X' } })
|
return cmdFn({ command: { arg: 'X' } })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
expect(mockClient.reply.args[0][0]).to.equal(501);
|
expect(mockClient.reply.args[0][0]).to.equal(501);
|
||||||
expect(mockClient.encoding).to.equal(null);
|
expect(mockClient.transferType).to.equal(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user