天天看点

c#如何判断ftp服务器上文件夹是否存在,C#做FTP上传时,怎么判断 文件路径 是否存在?...

123456qqq

TA贡献1654条经验 获得超5个赞

1 private bool DirectoryExist(string URI)

2 {

3 FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(URI));

4 reqFTP.Credentials = new NetworkCredential("", "");

5 reqFTP.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;

6

7 reqFTP.UseBinary = true;

8 try

9 {

10 FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();

11 response.Close();

12 return true;

13 }

14 catch(Exception ex)

15 {

16 string e=ex.Message;

17 return false;

18 }

19 }

查看完整回答

继续阅读