File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,6 +77,9 @@ class ftpd {
7777 }
7878 }
7979
80+ this . lastSocketKey = 0
81+ this . openSockets = { }
82+
8083 // setup FTP on TCP
8184 this . _tcp = net . createServer ( )
8285 this . _tcp . on ( 'connection' , ( socket ) => this . Handler ( this , socket ) )
@@ -98,6 +101,7 @@ class ftpd {
98101 }
99102
100103 stop ( ) {
104+ Object . keys ( this . openSockets ) . forEach ( ( socketKey ) => this . openSockets [ socketKey ] . destroy ( ) )
101105 this . _tcp . close ( )
102106 this . _useTLS && this . _tls . close ( )
103107 }
@@ -125,6 +129,8 @@ class ftpd {
125129 Handler ( main , socket ) {
126130 const connectionInfo = `[${ socket . remoteAddress . replace ( / : : f f f f : / g, '' ) } ] [${ socket . remotePort } ]`
127131 const localAddr = socket . localAddress . replace ( / : : f f f f : / g, '' )
132+ const socketKey = ++ main . lastSocketKey
133+ main . openSockets [ socketKey ] = socket
128134 let authenticated = false
129135 let isSecure = socket . encrypted || false
130136 let protection = false
@@ -176,6 +182,7 @@ class ftpd {
176182 socket . on ( 'data' , dataHandler )
177183 socket . on ( 'error' , main . ErrorHandler )
178184 socket . on ( 'close' , ( ) => {
185+ delete main . openSockets [ socketKey ]
179186 main . DebugHandler ( `${ connectionInfo } FTP connection closed` )
180187 if ( ftpData ) {
181188 ftpData . close ( )
You can’t perform that action at this time.
0 commit comments