I specify the file with my hands, but I would like him to go into the folder and download from there all the zip files starting with certain characters. since I'm new to C # can't figure out how to do (
|
1 answer
Some FTP servers support mask filters, but not all, and it’s probably better to do it yourself, i.e. get a list of all files, and then filter in any way:
public static void Main () { var ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://localhost/"); ftpRequest.Credentials =new NetworkCredential("LOGIN","PASSWORD"); ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory; var response = (FtpWebResponse)ftpRequest.GetResponse(); var streamReader = new StreamReader(response.GetResponseStream()); var Files = new List<string>(); string line = streamReader.ReadLine(); while (!string.IsNullOrEmpty(line)) { Files.Add(line); line = streamReader.ReadLine(); } streamReader.Close(); foreach (var F in Files) if (F.StartsWith("n") && (F.EndsWith(".zip"))) Console.WriteLine(F); }
See also this question.
- Thank you so much! =) Everything is clear and works) - Side Kick
|