-1

I'm developing a system that need to download binary files from a server folder. In here I will check before downloading whether they are in my local folder.so I need to get list of the *.bin files.

I have tried code in below, but it generate list all the files that on server folder.

    private string[] GetRemoteFileList()
    {
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(_remoteHost));
        request.Credentials = new NetworkCredential(_remoteUser, _remotePass);
        request.Method = WebRequestMethods.Ftp.ListDirectory;

        FtpWebResponse response = (FtpWebResponse)request.GetResponse();
        Stream responseStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(responseStream);

        string FileNames = reader.ReadToEnd();
        string[] Files = Regex.Split(FileNames, "\r\n");
        return Files;
    }

What I need is filter out only *.bin files. How can I achieve this?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
iJay
  • 4,205
  • 5
  • 35
  • 63

1 Answers1

2

What have you tried?

You have now in Files an array of all files in the current directory. Why don't you filter that list? For example:

return Files.Where(
    f => f.EndsWith(".bin", StringComparison.OrdinalIgnoreCase)
                  ).ToList();
CodeCaster
  • 147,647
  • 23
  • 218
  • 272