def test_NLST(self):
        """
        Test the NLST command in non-passive mode.

        L{ftp.FTPClient.nlst} should return a Deferred which fires with a
        list of filenames when the list command has completed.
        """
        self.client.passive = False
        def generatePort(portCmd):
            portCmd.text = 'PORT %s' % (ftp.encodeHostPort('127.0.0.1', 9876),)
            portCmd.protocol.makeConnection(proto_helpers.StringTransport())
            self.client.lineReceived(
                b'150 File status okay; about to open data connection.')
            portCmd.protocol.dataReceived(b'foo\r\n')
            portCmd.protocol.dataReceived(b'bar\r\n')
            portCmd.protocol.dataReceived(b'baz\r\n')
            portCmd.protocol.connectionLost(
                failure.Failure(error.ConnectionDone("")))

        def cbList(res, proto):
            fls = proto.buffer.decode(self.client._encoding).splitlines()
            expected = ["foo", "bar", "baz"]
            expected.sort()
            fls.sort()
            self.assertEqual(fls, expected)

        self.client.generatePortCommand = generatePort
        self._testLogin()
        lstproto = _BufferingProtocol()
        d = self.client.nlst('foo/bar', lstproto).addCallback(cbList, lstproto)
        self.assertEqual(self.transport.value(), ('PORT %s\r\n' %
            (ftp.encodeHostPort('127.0.0.1', 9876),)).encode(
                self.client._encoding))
        self.transport.clear()
        self.client.lineReceived(b'200 PORT OK')
        self.assertEqual(self.transport.value(), b'NLST foo/bar\r\n')
        self.client.lineReceived(b'226 Transfer Complete.')
        return d

        Test the NLST command in non-passive mode.

        L{ftp.FTPClient.nlst} should return a Deferred which fires with a
        list of filenames when the list command has completed.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_ftp.py