I'm running a check to see if a directory exists on my FTP server:
public bool DirectoryExists(string directory)
{
bool directoryExists;
var request = (FtpWebRequest)WebRequest.Create(directory);
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential("user", "pass");
try
{
using (request.GetResponse())
{
directoryExists = true;
}
}
catch (WebException)
{
directoryExists = false;
}
return directoryExists;
}
In this case:
directory = @"ftp://ftp.example.com/Rubicon";
On my server, I have a folder named Rubicon1
. This is causing my check to return true
. How can I ensure that it fails unless it matches the directory name exactly?
Create
is for creating the FTP web request, not the actual FTP Directory – ReconditionRubicon
, the check passes. – CambricWebRequestMethods.Ftp.MakeDirectory
for the desired path. If the response face failure, it'll return a550
error about accessing or finding the relative file/folder. – Manville