2010-01-06 52 views
0

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

像C:\ Program Files文件\ FTPROOT,如下图所示:

alt text

我想像它会是这样的:

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

任何想法?

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

+0

这篇文章可以帮助(IIS7只): - [自动化IIS管理与C#(http://forums.iis.net/t /1150298.aspx)第二个回复中的代码。 – GrayWizardx 2010-01-06 05:26:18

回答

0

对于IIS 6,至少,我发现它在注册表中的位置:

HKEY_LOCAL_MACHINE \ SYSTEM \ ControlSet001 \服务\ MSFTPSVC \参数\虚拟根\

数据的格式是有点怪 - 例如,d:\ FTPROOT ,, 1

alt text

+0

我很好奇D:\ ftproot ,, 1中间的值是什么。看起来最后一个值是读取和写入权限的总和,其中read = 1,write = 2。 – 2010-01-06 17:50:18

2

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

Technet

基本上,用户的主文件夹验证时由查询msIIS-FTPROOT和msIIS-FTPDir确定在Active Directory用户对象的属性。 msIIS-FTPRoot和msIIS-FTPDir值的连接会生成用户主文件夹的路径。

一个例子可以是这样的:

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

这将导致 “d:\ FTP用户\ 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(); 
     } 
+0

对不起,GetDC()定义在哪里? – 2010-01-06 06:19:14

+0

对不起。代码已更新。 – 2010-01-06 08:28:19

相关问题