I need to find all files and all subfolders in a directory. I am omitting the FtpWebRequest. Here is what I have written so far:
private string[] fileList () {
StringBuilder result = new StringBuilder();
WebResponse response = null;
FtpWebRequest reqFtp = null;
//makes request to ftp server
StreamReader reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
//reads everything in directory but does not open the subfolders
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
result.Remove(result.ToString().LastIndexOf('\n');
return result.ToString().Split('\n');
}
This shows me all files and folders within the specified directory. However, my question is: How do I read the files that are in each subfolder within this directory?
Is there a way of detecting that I've reached a folder so that I can save the path as an index in string[] perhaps, and keep reading until there are no more folders?
My intention is to overwrite each file on my local machine with the files found being read from the Ftp Server.