Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a18841d770 | ||
|
|
0dbb7f9070 |
@@ -75,7 +75,6 @@ __Default:__ `"ftp://127.0.0.1:21"`
|
||||
#### `pasv_url`
|
||||
The hostname to provide a client when attempting a passive connection (`PASV`). This defaults to the provided `url` hostname.
|
||||
|
||||
_Note:_ If set to `0.0.0.0`, this will automatically resolve to the external IP of the box.
|
||||
__Default:__ `"127.0.0.1"`
|
||||
|
||||
#### `pasv_min`
|
||||
|
||||
7
ftp-srv.d.ts
vendored
7
ftp-srv.d.ts
vendored
@@ -112,6 +112,13 @@ export class FtpServer extends EventEmitter {
|
||||
whitelist?: Array<string>
|
||||
}) => void,
|
||||
reject: (err?: Error) => void
|
||||
) => void): this;
|
||||
|
||||
on(event: "disconnect", listener: (
|
||||
data: {
|
||||
connection: FtpConnection,
|
||||
id: string
|
||||
}
|
||||
) => void): this;
|
||||
|
||||
on(event: "client-error", listener: (
|
||||
|
||||
@@ -40,8 +40,8 @@ class FtpServer extends EventEmitter {
|
||||
_.get(this, 'options.pasv_min'),
|
||||
_.get(this, 'options.pasv_max'));
|
||||
|
||||
const timeout = Number(this.options.timeout);
|
||||
this.options.timeout = isNaN(timeout) ? 0 : Number(timeout);
|
||||
const timeout = Number(this.options.timeout);
|
||||
this.options.timeout = isNaN(timeout) ? 0 : Number(timeout);
|
||||
|
||||
const serverConnectionHandler = (socket) => {
|
||||
socket.setTimeout(this.options.timeout);
|
||||
@@ -53,7 +53,7 @@ class FtpServer extends EventEmitter {
|
||||
const greeting = this._greeting || [];
|
||||
const features = this._features || 'Ready';
|
||||
return connection.reply(220, ...greeting, features)
|
||||
.finally(() => socket.resume());
|
||||
.finally(() => socket.resume());
|
||||
};
|
||||
const serverOptions = Object.assign({}, this.isTLS ? this.options.tls : {}, {pauseOnConnect: true});
|
||||
|
||||
@@ -119,6 +119,7 @@ class FtpServer extends EventEmitter {
|
||||
return new Promise((resolve) => {
|
||||
const client = this.connections[id];
|
||||
if (!client) return resolve();
|
||||
this.emit('disconnect', {connection: client, id});
|
||||
delete this.connections[id];
|
||||
try {
|
||||
client.close(0);
|
||||
|
||||
@@ -369,6 +369,39 @@ describe('Integration', function () {
|
||||
});
|
||||
}
|
||||
|
||||
describe('Server events', function () {
|
||||
const disconnect = sinon.spy();
|
||||
const login = sinon.spy();
|
||||
|
||||
before(() => {
|
||||
server.on('login', login);
|
||||
server.on('disconnect', disconnect);
|
||||
return connectClient({
|
||||
host: server.url.hostname,
|
||||
port: server.url.port,
|
||||
user: 'test',
|
||||
password: 'test'
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
server.off('login', login);
|
||||
server.off('disconnect', disconnect);
|
||||
})
|
||||
|
||||
it('should fire a login event on connect', () => {
|
||||
expect(login.calledOnce).to.be.true;
|
||||
});
|
||||
|
||||
it('should fire a close event on disconnect', (done) => {
|
||||
client.end();
|
||||
setTimeout(() => {
|
||||
expect(disconnect.calledOnce).to.be.true;
|
||||
done();
|
||||
}, 100)
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ASCII', function () {
|
||||
before(() => {
|
||||
return connectClient({
|
||||
|
||||
Reference in New Issue
Block a user