1

That's how I get file list from FTP:

FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(url);
ftpRequest.Credentials = new NetworkCredential(FtpUser, Password);
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
List<string> result = new List<string>();
using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
{
    string line = streamReader.ReadLine();
    while (!string.IsNullOrEmpty(line))
    {
        result.Add(line);
        line = streamReader.ReadLine();
    }
}

And if there are files with folders there on ftp like:

folder01_name
folder02_name
image.png
text.txt

Result will contain strings for all this names:

folder01_name
folder02_name
image.png
text.txt

I need to get files only somehow. Of course I can try to filter it somehow but it's not a good solution and sometimes files become without resolution, so it's very hard to find differense between file and folder names.

How do I solve it?

mr_blond
  • 1,586
  • 2
  • 20
  • 52
  • 3
    Use `WebRequestMethods.Ftp.ListDirectoryDetails` instead of WebRequestMethods.Ftp.ListDirectory. This would not only provide names, but also information about whether a name is a file or directory. You would then also need to parse the response differently. For details how you could do this, take a look at this thread: https://social.msdn.microsoft.com/Forums/vstudio/en-US/7758e7a8-e063-4eec-a6c1-c76a59d02852/listing-all-files-from-ftp-server-using-c?forum=csharpgeneral or search StackOverflow for "WebRequestMethods.Ftp.ListDirectoryDetails" (plenty of answers dealing with this) –  Nov 16 '18 at 16:33

0 Answers0