diff --git a/lib/server.js b/lib/server.js index 4f6fd1f6..21b08f7b 100644 --- a/lib/server.js +++ b/lib/server.js @@ -207,6 +207,14 @@ class Session extends EventEmitter { state: 'open' } }; + + // This is necessary to properly terminate the connection for some + // clients (ex: OpenSSH sftp) that send EOF when requesting to close the + // connection. + this.on('eof', () => { + if (this._channel instanceof SFTP) + this._channel.end(); + }); } } diff --git a/test/test-sftp.js b/test/test-sftp.js index 50e56f5d..72ba8511 100644 --- a/test/test-sftp.js +++ b/test/test-sftp.js @@ -46,6 +46,11 @@ setup('close', mustCall((client, server) => { })); })); +setup('eof', mustCall((client, server) => { + client.on('close', mustCall(() => {})); + client._protocol.channelEOF(client.outgoing.id); +})); + setup('read', mustCall((client, server) => { const expected = Buffer.from('node.jsnode.jsnode.jsnode.jsnode.jsnode.js'); const handle_ = Buffer.from('node.js');