Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. public bool DirectoryExists(string directory)
  2. {
  3. if (String.IsNullOrEmpty(directory))
  4. throw new ArgumentException("No directory was specified to check for");
  5.  
  6. // Ensure directory is ended with / to avoid false positives
  7. if (!directory.EndsWith("/"))
  8. directory += "/";
  9.  
  10. try
  11. {
  12. var request = (FtpWebRequest)WebRequest.Create(directory);
  13. request.Method = WebRequestMethods.Ftp.ListDirectory;
  14. request.Credentials = new NetworkCredential(Username, Password);
  15.  
  16. using (request.GetResponse())
  17. {
  18. return true;
  19. }
  20. }
  21. catch (WebException)
  22. {
  23. return false;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement