'This command causes a directory listing to be sent from the server to
the client. The pathname should specify a directory or other
system-specific file group descriptor. An empty path implies the current
working directory. If the path is non-existent, send nothing. If the
path is to a file, send only the file name.
@type path: C{str}
@param path: The path for which a directory listing should be returned.
@rtype: L{Deferred}
@return: a L{Deferred} which will be fired when the listing request
is finished.'

def ftp_NLST(self, path):

    if ((self.dtpInstance is None) or (not self.dtpInstance.isConnected)):
        return defer.fail(BadCmdSequenceError('must    send    PORT    or    PASV    before    RETR'))
    try:
        segments = toSegments(self.workingDirectory, path)
    except InvalidPath:
        return defer.fail(FileNotFoundError(path))
    def cbList(results, glob):
        '\n                                                Send,    line    by    line,    each    matching    file    in    the    directory    listing,    and\n                                                then    close    the    connection.\n\n                                                @type    results:    A    C{list}    of    C{tuple}.    The    first    element    of    each\n                                                                C{tuple}    is    a    C{str}    and    the    second    element    is    a    C{list}.\n                                                @param    results:    The    names    of    the    files    in    the    directory.\n\n                                                @param    glob:    A    shell-style    glob    through    which    to    filter    results    (see\n                                                                U{http://docs.python.org/2/library/fnmatch.html}),    or    L{None}\n                                                                for    no    filtering.\n                                                @type    glob:    L{str}    or    L{None}\n\n                                                @return:    A    C{tuple}    containing    the    status    code    for    a    successful\n                                                                transfer.\n                                                @rtype:    C{tuple}\n                                                '
        self.reply(DATA_CNX_ALREADY_OPEN_START_XFR)
        for (name, ignored) in results:
            if ((not glob) or (glob and fnmatch.fnmatch(name, glob))):
                name = self._encodeName(name)
                self.dtpInstance.sendLine(name)
        self.dtpInstance.transport.loseConnection()
        return (TXFR_COMPLETE_OK,)
    def listErr(results):
        '\n                                                RFC    959    specifies    that    an    NLST    request    may    only    return    directory\n                                                listings.    Thus,    send    nothing    and    just    close    the    connection.\n\n                                                @type    results:    L{Failure}\n                                                @param    results:    The    L{Failure}    wrapping    a    L{FileNotFoundError}    that\n                                                                occurred    while    trying    to    list    the    contents    of    a    nonexistent\n                                                                directory.\n\n                                                @returns:    A    C{tuple}    containing    the    status    code    for    a    successful\n                                                                transfer.\n                                                @rtype:    C{tuple}\n                                                '
        self.dtpInstance.transport.loseConnection()
        return (TXFR_COMPLETE_OK,)
    if _isGlobbingExpression(segments):
        glob = segments.pop()
    else:
        glob = None
    d = self.shell.list(segments)
    d.addCallback(cbList, glob)
    d.addErrback(listErr)
    return d
