次の方法で共有


FTP カスタム承認 <customAuthorization>

概要

<customAuthorization> 要素は、FTP サイトのカスタム承認の設定を指定します。 この形式の承認では、カスタム承認プロバイダーを使ってユーザー アクセスを検証します。

カスタム承認プロバイダーを有効にすると、組み込みの承認プロバイダーは使われなくなり、許可規則または拒否規則を手動で構成に追加できなくなります。

カスタム プロバイダーの作成方法については、「マネージド コード (C#) を使用して単純な FTP ホーム ディレクトリ プロバイダーを作成する方法」を参照してください。

互換性

バージョン メモ
IIS 10.0 <customAuthorization> 要素は、IIS 10.0 では変更されませんでした。
IIS 8.5 <customAuthorization> 要素は、IIS 8.5 では変更されませんでした。
IIS 8.0 <customAuthorization> 要素は IIS 8.0 で導入されました。
IIS 7.5 該当なし
IIS 7.0 該当なし
IIS 6.0 該当なし

段取り

FTP サイト上のカスタム プロバイダーを使った FTP 承認をサポートするには、[FTP 拡張] とともに [FTP Service] をインストールする必要があります。

Windows Server 2012

  1. Windows キーを押してから、[サーバー マネージャー] をクリックします。

  2. サーバー マネージャーで、[管理] をクリックし、[役割と機能の追加] をクリックします。

  3. 役割と機能の追加ウィザードで次のように操作します。

    • [開始する前に] ページで [次へ] をクリックします。
    • [インストールの種類] ページでインストールの種類を選んでから、[次へ] をクリックします。
    • [サーバーの選択] ページで適切なサーバーを選んでから、[次へ] をクリックします。
    • [サーバーの役割] ページで、[Web サーバー (IIS)] がオンになっていることを確認してから、展開します。
    • [FTP サーバー] を展開し、[FTP Service][FTP 拡張] の両方をオンにしてから、[次へ] をクリックします。
    • [機能] ページで [次へ] をクリックします。
    • [インストール オプションの確認] ページで、[インストール] をクリックします。
    • [結果] ページで、 [閉じる]をクリックします。

Windows 8

  1. Windows のコントロール パネルを開きます。
  2. Windows コントロール パネルで、[プログラムと機能] を開きます。
  3. [Programs and Features]\(プログラムと機能\) で、[Turn Windows features on or off]\(Windows 機能を有効または無効にする\) をクリックします。
  4. [Windows の機能] ダイアログ ボックスで、[インターネット インフォメーション サービス] を展開してから、[FTP サーバー] を展開します。
  5. [FTP サーバー][FTP Service][FTP 拡張] をオンにしてから、[OK] をクリックします。

操作方法

カスタム プロバイダーに基づいて FTP 承認を構成する方法

  1. 次のようにインターネット インフォメーション サービス (IIS) マネージャーを開きます。

    • Windows Server 2012 以降を使用している場合:

      • タスク バーで、[サーバー マネージャー][ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
    • Windows 8 以降を使用している場合:

      • Windows キーを押しながら文字 X を押し、次に [コントロール パネル] をクリックします。
      • [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
  2. [接続] ウィンドウで、サーバー名を選び、[サイト] を展開してから、FTP サイトを選びます。

  3. [ホーム] ペインで [FTP の承認規則] 機能をダブルクリックします。

  4. [操作] ウィンドウで [機能設定の編集] をクリックします。

  5. [承認の機能設定] ダイアログ ボックスで、[カスタム承認プロバイダーを選択する] を選択して、カスタム プロバイダーによる FTP 承認を有効にします。 関連付けられているドロップダウン リストで、リストからカスタム プロバイダーを選びます。

    [認証機能の設定] ダイアログ ボックスのスクリーンショット。

    Note

    カスタム FTP 承認プロバイダーを有効にすると、[FTP の承認規則] 機能が無効になります。

  6. OK をクリックします。

構成

属性

なし。

子要素

要素 説明
provider 省略可能な要素です。

カスタム承認プロバイダーを指定します。

構成サンプル

次のサンプルは、<customAuthorization> 要素を示しています。

<ftpServer>
   <security>
      <customAuthorization>
         <provider name="MyProvider" enabled="true" />
      </customAuthorization>
   </security>
</ftpServer>

次のサンプルは、前の例のカスタム承認プロバイダーの <providerDefinitions> 要素を示しています。

<system.ftpServer>
   <providerDefinitions>
      <add name="MyProvider" type="MyProvider, MyProvider, version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73" />
   </providerDefinitions>
</system.ftpServer>

サンプル コード

次のコード サンプルは、カスタム承認プロバイダーを構成します。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/sites /[name='MyFTPSite'].ftpServer.security.customAuthorization.provider.name:"MyProvider" /commit:apphost

appcmd.exe set config -section:system.applicationHost/sites /[name='MyFTPSite'].ftpServer.security.customAuthorization.provider.enabled:"True" /commit:apphost

Note

AppCmd.exe を使用してこれらの設定を構成する場合は、commit パラメーターを必ず apphost に設定する必要があります。 これにより、ApplicationHost.config ファイルの適切な ___location セクションに構成設定がコミットされます。

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample {

    private static void Main() {
        
        using(ServerManager serverManager = new ServerManager()) { 
            Configuration config = serverManager.GetApplicationHostConfiguration();
            
            ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");
            
            ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
            
            ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"MyFTPSite");
            if (siteElement == null) throw new InvalidOperationException("Element not found!");
            
            
            ConfigurationElement ftpServerElement = siteElement.GetChildElement("ftpServer");
            
            ConfigurationElement securityElement = ftpServerElement.GetChildElement("security");
            
            ConfigurationElement customAuthorizationElement = securityElement.GetChildElement("customAuthorization");
            
            ConfigurationElement providerElement = customAuthorizationElement.GetChildElement("provider");
            providerElement["name"] = @"MyProvider";
            providerElement["enabled"] = true;
            
            serverManager.CommitChanges();
        }
    }
    
    private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues) {
        foreach (ConfigurationElement element in collection) {
            if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase)) {
                bool matches = true;
    
                for (int i = 0; i < keyValues.Length; i += 2) {
                    object o = element.GetAttributeValue(keyValues[i]);
                    string value = null;
                    if (o != null) {
                        value = o.ToString();
                    }
    
                    if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase)) {
                        matches = false;
                        break;
                    }
                }
                if (matches) {
                    return element;
                }
            }
        }
        return null;
    }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration
Module Sample
     
     Sub Main()
         Dim serverManager As ServerManager = New ServerManager
         Dim config As Configuration = serverManager.GetApplicationHostConfiguration
         Dim sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")
         Dim sitesCollection As ConfigurationElementCollection = sitesSection.GetCollection
         Dim siteElement As ConfigurationElement = FindElement(sitesCollection, "site", "name", "MyFTPSite")
         If (siteElement Is Nothing) Then
             Throw New InvalidOperationException("Element not found!")
         End If
         Dim ftpServerElement As ConfigurationElement = siteElement.GetChildElement("ftpServer")
         Dim securityElement As ConfigurationElement = ftpServerElement.GetChildElement("security")
         Dim customAuthorizationElement As ConfigurationElement = securityElement.GetChildElement("customAuthorization")
         Dim providerElement As ConfigurationElement = customAuthorizationElement.GetChildElement("provider")
         providerElement("name") = "MyProvider"
         providerElement("enabled") = true
         serverManager.CommitChanges
     End Sub
     
     Private Shared Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ParamArray ByVal keyValues() As String) As ConfigurationElement
         For Each element As ConfigurationElement In collection
             If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then
                 Dim matches As Boolean = true
                 Dim i As Integer = 0
                 Do While (i < keyValues.Length)
                     Dim o As Object = element.GetAttributeValue(keyValues(i))
                     Dim value As String = Nothing
                     If (Not (o) Is Nothing) Then
                         value = o.ToString
                     End If
                     If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then
                         matches = false
                         Exit For
                     End If
                     i = (i + 2)
                 Loop
                 If matches Then
                     Return element
                 End If
             End If
         Next
         Return Nothing
     End Function
 End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");

var sitesCollection = sitesSection.Collection;

var siteElementPos = FindElement(sitesCollection, "site", ["name", "MyFTPSite"]);
if (siteElementPos == -1) throw "Element not found!";
var siteElement = sitesCollection.Item(siteElementPos);

var ftpServerElement = siteElement.ChildElements.Item("ftpServer");
var securityElement = ftpServerElement.ChildElements.Item("security");
var customAuthorizationElement = securityElement.ChildElements.Item("customAuthorization");
var providerElement = customAuthorizationElement.ChildElements.Item("provider");
providerElement.Properties.Item("name").Value = "MyProvider";
providerElement.Properties.Item("enabled").Value = true;

adminManager.CommitChanges();


function FindElement(collection, elementTagName, valuesToMatch) {
    for (var i = 0; i < collection.Count; i++) {
        var element = collection.Item(i);
        
        if (element.Name == elementTagName) {
            var matches = true;
            for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
                var property = element.GetPropertyByName(valuesToMatch[iVal]);
                var value = property.Value;
                if (value != null) {
                    value = value.toString();
                }
                if (value != valuesToMatch[iVal + 1]) {
                    matches = false;
                    break;
                }
            }
            if (matches) {
                return i;
            }
        }
    }
    
    return -1;
}

VBScript

Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")

Set sitesCollection = sitesSection.Collection
siteElementPos = FindElement(sitesCollection, "site", Array ("name", "MyFTP"))
if (siteElementPos = -1) THEN throw "Element not found!"
Set siteElement = sitesCollection.Item(siteElementPos)

Set ftpServerElement = siteElement.ChildElements.Item("ftpServer")
Set securityElement = ftpServerElement.ChildElements.Item("security")
Set customAuthorizationElement = securityElement.ChildElements.Item("customAuthorization")
Set providerElement = customAuthorizationElement.ChildElements.Item("provider")
providerElement.Properties.Item("name").Value = "MyProvider1"
providerElement.Properties.Item("enabled").Value = true

adminManager.CommitChanges()

Function FindElement(collection, elementTagName, valuesToMatch)
   For i = 0 To CInt(collection.Count) - 1
      Set element = collection.Item(i)
      If element.Name = elementTagName Then
         matches = True
         For iVal = 0 To UBound(valuesToMatch) Step 2
            Set property = element.GetPropertyByName(valuesToMatch(iVal))
            value = property.Value
            If Not IsNull(value) Then
               value = CStr(value)
            End If
            If Not value = CStr(valuesToMatch(iVal + 1)) Then
               matches = False
               Exit For
            End If
         Next
         If matches Then
            Exit For
         End If
      End If
   Next
   If matches Then
      FindElement = i
   Else
      FindElement = -1
   End If
End Function

PowerShell

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/sites/site[@name='MyFTPSite']/ftpServer/security/customAuthorization/provider" -name "name" -value "MyProvider"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/sites/site[@name='MyFTPSite']/ftpServer/security/customAuthorization/provider" -name "enabled" -value "True"