I am using FTP to upload files to a folder on an FTP server folder, but first I need to determine that the folder exists. MSDN contains an example of how to use FtpWebResponse to check if a folder exists:
public class WebRequestGetExample
{
public static void Main ()
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/");
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("Directory List Complete, status {0}", response.StatusDescription);
reader.Close();
response.Close();
}
}
Using the code above, one can obtain a list of folders off the root level of the server, and I can do this in my own situation. That is NOT my question.
My question is, what if the folder I am wanting to write to is a SUBFOLDER of one of the folders that results from the call to ListDirectoryDetails? How do I dig deeper into the folder structure?