C#如何判断远程目录(FTP服务器)是否存在?

参考地址:http://www.ggat.cn/newsInfo.html/129

 

直接使用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)    {        //不存在    }}

转载于:https://my.oschina.net/u/3740241/blog/1583720

你可能感兴趣的:(c#)