C# .NET - Regarding URI path format in FTPWebRequest

Asked By kughan j on 24-Apr-15 08:58 AM

I am using the following to read the files from the FTP root location.

FtpWebRequest Request = (FtpWebRequest)WebRequest.Create(FtpServer);
            Request.Method = WebRequestMethods.Ftp.ListDirectory;
            Request.Credentials = new NetworkCredential(UserID, Password);
            FtpWebResponse Response = (FtpWebResponse)Request.GetResponse();
            Stream ResponseStream = Response.GetResponseStream();
            StreamReader Reader = new StreamReader(ResponseStream);

My question is if I use the FTP path as  ftp://slnxblysap035/test/  it works fine and reads from the test folder.

But I want to read from the root location so i am using  ftp://slnxblysap035/ which gives me error as 
"length cannot be less than zero"

Please suggest what is the path format i should to read from the root location??



Robbe Morris replied to kughan j on 24-Apr-15 09:04 AM
ftp has an mget method with arguments to get child folders.  See if the Request object has some sort of flag to iterate through all the folders and child folders.  I'm not sure if the FtpWebRequest class supports recursion (iterating through child folders).

Check out WebRequestMethods.Ftp.ListDirectoryDetails to see about getting a list of files and folders to iterate through.