Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool DirectoryExists(string directory)
- {
- if (String.IsNullOrEmpty(directory))
- throw new ArgumentException("No directory was specified to check for");
- // Ensure directory is ended with / to avoid false positives
- if (!directory.EndsWith("/"))
- directory += "/";
- try
- {
- var request = (FtpWebRequest)WebRequest.Create(directory);
- request.Method = WebRequestMethods.Ftp.ListDirectory;
- request.Credentials = new NetworkCredential(Username, Password);
- using (request.GetResponse())
- {
- return true;
- }
- }
- catch (WebException)
- {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement