直接使用FTPWebRequest类:

var request = (FtpWebRequest)WebRequest.Create(”ftp://ipaddress//dir");
request.Credentials = new NetworkCredential("user", "pass");
request.Method = WebRequestMethods.Ftp.GetFileSize;
 
try
{
    FtpWebResponse response = (FtpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
    FtpWebResponse response = (FtpWebResponse)ex.Response;
    if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
    {
        //不存在
    }
}
已赞 2 0 评论