【问题标题】:C# - is there a way to get the local path of the Default FTP site?C# - 有没有办法获取默认 FTP 站点的本地路径?
【发布时间】:2010-01-06 05:18:15
【问题描述】:

有没有办法以编程方式获取默认 FTP 站点(在 IIS 中)的本地路径?

如C:\program files\ftproot,如下图:

我想它会是这样的:

DirectoryEntry ftproot = new DirectoryEntry("IIS://localhost/MSFTPSVC/1/Root");
string directory; // = ftproot.something

有什么想法吗?

编辑:这适用于 IIS 6.0。当然,这必须存储在某个地方 - 也许在注册表中?

【问题讨论】:

标签: c# active-directory iis-6 ftp directoryentry


【解决方案1】:

据我所知,有两个 Active Directory 属性:msIIS-FTPRoot、msIIS-FTPDir。

来自Technet

基本上,用户的主文件夹是通过在 Active Directory 中查询用户对象的 msIIS-FTPRoot 和 msIIS-FTPDir 属性来确定的。 msIIS-FTPRoot 和 msIIS-FTPDir 值的串联产生用户主文件夹的路径。

一个例子可能如下所示:

  msIIS-FTPRoot = D:\FTP Users
  msIIS-FTPDir = \JohnSmith

这将导致“D:\FTP Users\JohnSmith”作为用户的主文件夹。

遍历所有用户和默认目录的代码:

    static void Main(string[] args)
            {            
                string domain = Environment.GetEnvironmentVariable("USERDNSDOMAIN");
                string dc = GetDC(domain);
                string ldap = String.Format("LDAP://{0}/{1}", domain, dc);
                DirectoryEntry e = new DirectoryEntry(ldap);

                DirectorySearcher src = new DirectorySearcher(e, "(objectClass=user)");
                SearchResultCollection res = src.FindAll();
                foreach (SearchResult r in res)
                {
                    DirectoryEntry f = r.GetDirectoryEntry();
                    Console.WriteLine(f.Name + "\t" + f.Properties["msIIS-FTPRoot"].Value + f.Properties["msIIS-FTPDir"].Value);
                }
                Console.ReadKey();
            }

private static string GetDC(string domain)
        {
            StringBuilder sb = new StringBuilder(domain);
            sb.Replace(".", ",DC=");
            sb.Insert(0, "DC=");
            return sb.ToString();
        }

【讨论】:

  • 抱歉,GetDC() 是在哪里定义的?
【解决方案2】:

至少对于 IIS 6,我在这里的注册表中找到了它:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\MSFtpsvc\Parameters\Virtual Roots\

数据的格式有点奇怪 - 例如,D:\ftproot,,1

【讨论】:

  • 我很好奇 D:\ftproot,,1 中的中间值是什么。看起来最后一个值是读取和写入权限的总和,其中读取 = 1,写入 = 2。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-13
  • 1970-01-01
  • 1970-01-01
  • 2015-01-10
  • 2017-08-12
  • 2018-07-25
  • 1970-01-01
相关资源
最近更新 更多