Server 2008+ では、FTP サイトの仮想ディレクトリ Reports に新しいフォルダーをプログラムで作成しています。次のコマンドを使用して、新しいファイル パスごとに新しい FTP 承認規則を作成できます。
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection authorizationSection = config.GetSection("system.ftpServer/security/authorization", "FTP/LDNClient/Reports/aClientPath");
ConfigurationElementCollection authorizationCollection = authorizationSection.GetCollection();
ConfigurationElement addElement = authorizationCollection.CreateElement("add");
addElement["accessType"] = @"Allow";
addElement["users"] = @"LDNClient";
addElement["roles"] = @"";
addElement["permissions"] = @"Read, Write";
authorizationCollection.Add(addElement);
serverManager.CommitChanges();
}
ここで、「FTP/LDNClient/Reports/aClientPath」はルールのパスです。ただし、パスが異なる同じユーザーの要素が多数あります。applicationHost.config を開くと、「aClientPath」のようなパスを持つさまざまな ConfigurationElements が表示されます。
<location path="FTP/LDNClient/Reports/aClientPath">
<system.ftpServer>
<security>
<authorization>
<remove users="LDNClient" roles="" permissions="Write" />
<add accessType="Allow" users="LDNClient" permissions="Read, Write" />
</authorization>
</security>
</system.ftpServer>
</location>
しかし、その 1 つの要素を参照する方法がわからないので、(1) 要素を削除するか、(2) 権限を変更することができます。次のコマンドを使用して、各ノードをロールスルーできます。
foreach (ConfigurationElement item in authorizationCollection)
{
// Do something with item here
}
しかし、「item」で aClientPath のパスを見つけることができます。上記の場所ノードを使用して、どのように削除したり、権限を変更したりできますか?