Wednesday, July 20, 2011

check directory Exists in Ftp Server

 

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

        {

            bool IsExists = true;

            try

            {

                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( "ftp://domain.com/test",
                                                    txtUsername.Text, txtPassword.Text);

0 comments:

Post a Comment