Implement FTP directory listing command (NLST) command in custom VB.NET FTP server
14:08 26 Jan 2024

I am trying to program an FTP daemon using VB.NET. When the client sends the NLST command to get the files or folders in the path, the daemon sends each file or folder name one at a time (I have to write in each time ls to get the name of one file or folder only), I tried many methods and they did not work. Please help me, thank you.

This is the code I use:

Case "NLST"
    Dim str As New StringBuilder()
    Dim di = New DirectoryInfo(work_dir)

    For Each file In di.EnumerateFileSystemInfos()
        str.Append(file.Name).Append(Environment.NewLine)
    Next
    SendResponse(writer, str.ToString().TrimEnd)

When I run the program and type the ls command from the command prompt, it sends NLST command instead, which is very normal, but the problem is that my program sends one file every time I type the ls command in CMD.

windows vb.net cmd ftp