10

我正在检查我的 FTP 服务器上是否存在目录:

    public bool DirectoryExists(string directory)
    {
        bool directoryExists;

        var request = (FtpWebRequest)WebRequest.Create(directory);
        request.Method = WebRequestMethods.Ftp.ListDirectory;
        request.Credentials = new NetworkCredential("user", "pass");

        try
        {
            using (request.GetResponse())
            {
                directoryExists = true;
            }
        }
        catch (WebException)
        {
            directoryExists = false;
        }

        return directoryExists;
    }

在这种情况下:

directory = @"ftp://ftp.example.com/Rubicon";

在我的服务器上,我有一个名为Rubicon1. 这导致我的支票退回true。除非它与目录名称完全匹配,否则如何确保它失败?

4

1 回答 1

6

我通过将目录更改为:

directory = @"ftp://ftp.example.com/Rubicon/";
于 2013-02-01T16:06:30.163 回答