判断ftp文件夹是否存在
连接ftp
string url="ftp://127.0.01/Main/Test/";
private string FtpUserID;
private string FtpPassword;
FtpWebRequest reqFTP;
private void Connect(String url)//连接ftp
{
// 根据uri创建FtpWebRequest对象
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(url));
// 指定数据传输类型
reqFTP.UseBinary = true;
// ftp用户名和密码
reqFTP.Credentials = new NetworkCredential(FtpUserID, FtpPassword);
}
判断ftp文件夹是否存在
///
/// 判断ftp文件夹是否存在
///
///
///
public bool CheckDirectory(string Url)
{
bool Exists= false;
try
{
Connect(Url);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
response.Close();
Exists= true;
}
catch (WebException e)
{
if (e.HResult == -2146233079)
{
return Exists;
}
throw;
}
return Exists;
}