I used a class for all my FTP transfers witch work fine in C# 3.5 but since I updaded to the framework 4, I have some problems.
I search on Google but find no solutions.
Especially with a method to check if a directory exists :
public bool DirectoryExists(string directory)
{
bool directoryExists = false;
if (directory.Substring(0, 1) != "/")
directory = "/" + directory;
FtpWebRequest request = GetFtpWebRequest(host + directory, WebRequestMethods.Ftp.PrintWorkingDirectory);
try
{
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
directoryExists = true;
}
}
catch (WebException)
{
directoryExists = false;
}
return directoryExists;
}
private FtpWebRequest GetFtpWebRequest(string url, string method)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(url);
request.UseBinary = true;
request.KeepAlive = true;
request.UsePassive = (mode == Modes.Passive);
request.Timeout = Timeout.Infinite;
request.ServicePoint.ConnectionLimit = 6;
request.ReadWriteTimeout = Timeout.Infinite;
if (credential == null)
credential = new NetworkCredential(login, password);
request.Credentials = credential;
request.Method = method;
return request;
}
The method DirectoryExists always return true (even the directory does not exist) but only on the framework 4, before a exception was thrown by GetFtpWebRequest if the directory does not exists.
Does anyone had this problem ?
Please don't tell me to use an other library cause all my programs depend of this one and I don't want to update all ...