Wednesday, July 20, 2011

check directory Exists in Ftp Server


public bool FtpDirectoryExists(string directoryPath, string ftpUser, string ftpPassword)


            bool IsExists = true;



                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(directoryPath);

                request.Credentials = new NetworkCredential(ftpUser, ftpPassword);

                request.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;


                FtpWebResponse response = (FtpWebResponse)request.GetResponse();


            catch (WebException ex)


                IsExists = false;


            return IsExists;



I have called this method as:
bool result = FtpActions.Default.FtpDirectoryExists( "",
                                                    txtUsername.Text, txtPassword.Text);


  1. thanks....
    i found here...
    you're save my time dud!!!!

  2. I was using a similar approach, but now it's no longer working. FtpWebRequest.GetResponse() no longer seems to throw an exception when called for a directory that doesn't exist. The only change I can think of since it worked is that I've upgraded to Visual Studio 2013.