小编fin*_*min的帖子

C#检查FTP目录是否存在

我有这个FTP方法,检查目录是否存在.它在开始时工作正常,但现在,即使目录不存在,它仍然返回true.我尝试了很多东西,并设置断点以查看响应对象的哪些属性可用于确定目录是否存在.我也搜索了互联网,解决方案似乎对我不起作用.这是我的FTP方法.

public bool directoryExists(string directory)
            {
                /* Create an FTP Request */
                ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + directory);
                /* Log in to the FTP Server with the User Name and Password Provided */
                ftpRequest.Credentials = new NetworkCredential(user, pass);
                /* Specify the Type of FTP Request */
                ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                try
                {
                    using (ftpRequest.GetResponse())
                    {
                        return true;
                    }
                    //var response = ftpRequest.GetResponse();
                    //if (response != null)
                    //    return true;
                    //else return false;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    return false; …
Run Code Online (Sandbox Code Playgroud)

c# directory ftp exists

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

directory ×1

exists ×1

ftp ×1