C#做FTP上传时,怎么判断 文件路径 是否存在
1个回答
推荐于2016-04-14 · 知道合伙人软件行家
关注
展开全部
var request = (FtpWebRequest)WebRequest.Create
("<a href="ftp://ftp.domain.com/doesntexist.txt"" target="_blank">ftp://ftp.domain.com/doesntexist.txt"</a>);
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)
{
//Does not exist
}
}
("<a href="ftp://ftp.domain.com/doesntexist.txt"" target="_blank">ftp://ftp.domain.com/doesntexist.txt"</a>);
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)
{
//Does not exist
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询