def getDTPPort(self, factory):
        """
        Return a port for passive access, using C{self.passivePortRange}
        attribute.
        """
        for portn in self.passivePortRange:
            try:
                dtpPort = self.listenFactory(portn, factory)
            except error.CannotListenError:
                continue
            else:
                return dtpPort
        raise error.CannotListenError('', portn,
            "No port available in range %s" %
            (self.passivePortRange,))

        Return a port for passive access, using C{self.passivePortRange}
        attribute.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/ftp.py