I want to get the list of files from FTP server with specific search pattern ( Ex: get all the files having pattern as "*.txt") and download these files only using C#.net.
Below is the code returning list of files from FTP server, please suggest the addition code required to achieve the required task.
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + coldata.Host + "/"));
//("ftp://" + coldata.host + "/"));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(coldata.Uid, coldata.Pwd);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
reqFTP.Timeout = System.Threading.Timeout.Infinite;
reqFTP.Proxy = null;
reqFTP.KeepAlive = true;
reqFTP.UsePassive = true;
FtpWebResponse res = (FtpWebResponse)reqFTP.GetResponse();
response = reqFTP.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
// to remove the trailing '\n'
result.Remove(result.ToString().LastIndexOf('\n'), 1);
downloadRes = true;
return result.ToString().Split('\n');
Thanks.