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);
bool result = FtpActions.Default.FtpDirectoryExists( "ftp://domain.com/test",
txtUsername.Text, txtPassword.Text);
thanks....
ReplyDeletei found here...
you're save my time dud!!!!
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.
ReplyDelete