次の方法で共有


FTP メッセージ <messages>

概要

<messages> 要素は、FTP サービスが FTP クライアントに表示するメッセージを指定するために使われます。 bannerMessagegreetingMessagemaxClientsMessage 属性に指定したメッセージは、FTP クライアントが FTP サイトに接続したときに表示され、exitMessage 属性で指定したメッセージは、FTP クライアントが FTP サイトから切断されたときに表示されます。

suppressDefaultBanner 属性を bannerMessage 属性と組み合わせて使うと、FTP サーバーの種類を偽装できます。 既定のバナーが抑制されており、バナー メッセージが bannerMessage 属性で指定されていない場合、FTP クライアントがサーバーに接続すると、FTP サーバーに空白のバナーが表示されます。

expandVariables 属性には、FTP メッセージに特定のユーザー変数セットを表示するかどうかを指定します。 この属性が true に設定されている場合、FTP サービスは FTP メッセージにユーザー変数を表示します。それ以外の場合は、すべてのメッセージ テキストが入力したとおりに表示されます。 サポートされているユーザー変数は次のとおりです。

User Variable (ユーザー変数) 説明
%BytesReceived% 現在のセッションで、サーバーからクライアントに送信されたバイト数。
%BytesSent% 現在のセッションで、クライアントからサーバーに送信されたバイト数。
%SessionID% 現在のセッションの一意の識別子。
%SiteName% 現在のセッションをホストしている FTP サイトの名前。
%UserName% 現在ログオンしているユーザーのアカウント名。

allowLocalDetailedErrors 属性には、FTP クライアントがサーバー自体の FTP サーバーに接続されているときに、詳細なエラー メッセージを表示するかどうかを指定します。 これらのエラー メッセージには、サーバー管理者が問題のトラブルシューティングに使用できる詳細情報が含まれています。 この属性が true に設定されている場合、FTP サービスはローカル ホストにのみ詳細なエラー メッセージを表示します。それ以外の場合、詳細なエラー メッセージは表示されません。

互換性

バージョン メモ
IIS 10.0 <messages> 要素は、IIS 10.0 では変更されませんでした。
IIS 8.5 <messages> 要素は、IIS 8.5 では変更されませんでした。
IIS 8.0 <messages> 要素は IIS 8.0 では変更されませんでした。
IIS 7.5 <ftpServer> 要素の <messages> 要素は、IIS 7.5 の機能として付属しています。
IIS 7.0 <ftpServer> 要素の <messages> 要素が、IIS 7.0 用の別個のダウンロードとして FTP 7.0 で導入されました。
IIS 6.0 該当なし

Note

FTP 7.0 サービスと FTP 7.5 サービスは IIS 7.0 とは別に出荷され、次の URL からモジュールをダウンロードしてインストールする必要がありました。

https://www.iis.net/expand/FTP

Windows 7 と Windows Server 2008 R2 では、FTP 7.5 サービスは IIS 7.5 の機能として付属しているため、FTP サービスのダウンロードは必要なくなりました。

段取り

Web サーバーの FTP 公開をサポートするには、FTP サービスをインストールする必要があります。 そのためには、次のステップに従います。

Windows Server 2012 または Windows Server 2012 R2

  1. タスク バーで [サーバー マネージャー]をクリックします。

  2. [サーバー マネージャー] で、[管理] メニューを選択し、[役割と機能の追加] を選択します。

  3. [役割と機能の追加] ウィザードで、[次へ] をクリックします。 インストールの種類を選択し、[次へ] をクリックします。 対象サーバーを選択し、[次へ] をクリックします。

  4. [サーバーの役割] ページで、[Web サーバー (IIS)] を展開して、[FTP サーバー] を選びます。

    Note

    FTP サービスに対して ASP.NET メンバーシップ認証または IIS マネージャー認証をサポートするには、[FTP Service] に加えて[FTP 拡張] も選択する必要があります。
    Windows Server 2012 インターフェイスで選択された F T P サービスと F T P 拡張機能のスクリーンショット。 .

  5. [次へ] をクリックし、[機能の選択] ページで再度 [次へ] をクリックします。

  6. [インストール オプションの確認] ページで、[インストール] をクリックします。

  7. [結果] ページで、 [閉じる]をクリックします。

Windows 8 または Windows 8.1

  1. [スタート] 画面で、ポインターを左下隅まで移動し、[スタート] ボタンを右クリックし、[コントロール パネル] をクリックします。

  2. [コントロール パネル][プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。

  3. [インターネット インフォメーション サービス] を展開し、[FTP サーバー] を展開します。

    Note

    FTP サービスに対して ASP.NET メンバーシップ認証または IIS マネージャー認証をサポートするには、[FTP 拡張] も選択する必要があります。
    Windows 8 インターフェイスで選択された F T P サービスと F T P 拡張機能のスクリーンショット。

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

  5. 閉じるをクリックします。

Windows Server 2008 R2

  1. タスク バーで [スタート] をクリックし、[管理ツール] をポイントして、[サーバー マネージャ] をクリックします。

  2. [サーバー マネージャ] 階層ウィンドウで [役割] を展開し、[Web サーバー (IIS)] をクリックします。

  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールし、[役割サービスの追加] をクリックします。

  4. [役割サービスの追加] ウィザード[役割サービスの選択] ページで [FTP サーバー] を展開します。

  5. [FTP Service] を選択します。

    Note

    FTP サービスに対して ASP.NET メンバーシップ認証または IIS マネージャー認証をサポートするには、[FTP 拡張] も選択する必要があります。
    Windows Server 2008 インターフェイスで選択された F T P サービスと F T P 拡張機能のスクリーンショット。

  6. 次へ をクリックします。

  7. [インストール オプションの確認] ページで、[インストール] をクリックします。

  8. [結果] ページで、 [閉じる]をクリックします。

Windows 7

  1. タスク バーで、[スタート][コントロール パネル] の順にクリックします。

  2. [コントロール パネル][プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。

  3. [インターネット インフォメーション サービス][FTP サーバー] の順に展開します。

  4. [FTP Service] を選択します。

    Note

    FTP サービスに対して ASP.NET メンバーシップ認証または IIS マネージャー認証をサポートするには、[FTP 拡張] も選択する必要があります。
    Windows 7 インターフェイスで選択された F T P サービスと F T P 拡張機能のスクリーンショット。

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

Windows Server 2008 または Windows Vista

  1. 次の URL からインストール パッケージをダウンロードします。

  2. 次のチュートリアルの手順に従って、FTP サービスをインストールします。

操作方法

FTP サイトに対してカスタマイズされたメッセージを構成する方法

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

    • Windows Server 2012 または Windows Server 2012 R2 を使用している場合:

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

      • Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
      • [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
    • Windows Server 2008 または Windows Server 2008 R2 を使用している場合:

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

      • タスク バーで、[スタート][コントロール パネル] の順にクリックします。
      • [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
  2. [接続] ウィンドウでサーバー名を展開し、[サイト] ノードを展開してから、サイトの名前をクリックします。

  3. サイトの [ホーム] ウィンドウで、[FTP メッセージ] 機能をダブルクリックします。
    Web サイトの [ホーム] ウィンドウで選択されている [F T P メッセージ] オプションのスクリーンショット。

  4. 次のオプションを構成します:

    • [既定のバナーを表示しない] オプションをクリックしてオンにします。
    • [メッセージ内のユーザー変数をサポートする] オプションをクリックしてオンにします。
    • [バナー] メッセージに「This is my FTP server」と入力します。
    • [接続時のメッセージ] メッセージに「Hello %UserName%!」と入力します。
    • [接続切断時のメッセージ] メッセージに「Goodbye %UserName%!」と入力します。
      [F T P メッセージ] ウィンドウの [ローカル要求の詳細なメッセージを表示する] に設定された [メッセージの動作] のスクリーンショット。
  5. [操作] ペインで [適用] をクリックします。

構成

サイトレベルの <messages> 要素は、サイト レベルで構成されます。

属性

属性 説明
allowLocalDetailedErrors 省略可能で、 Boolean 型の属性。

詳細なエラー メッセージをローカルで表示する場合は true、それ以外の場合は false

注: 詳細なエラー メッセージをリモートで表示することはできません。

既定値は true です。
bannerMessage 省略可能な文字列属性。

クライアントが FTP サーバーに接続するときに表示されるメッセージを指定します。

既定値はありません。
exitMessage 省略可能な文字列属性。

クライアントが FTP サーバーへの接続を閉じるときに表示されるメッセージを指定します。

既定値はありません。
expandVariables 省略可能で、 Boolean 型の属性。

ユーザー変数を展開する必要がある場合は true、それ以外の場合は false

既定値は false です。
greetingMessage 省略可能な文字列属性。

クライアントが FTP サーバーにログインした後に表示されるメッセージを指定します。

既定値はありません。
maxClientsMessage 省略可能な文字列属性。

クライアントがログインしようとしたときに、FTP サーバー上のクライアントの最大数に既に達しているときに表示されるメッセージを指定します。

既定値はありません。
suppressDefaultBanner 省略可能で、 Boolean 型の属性。

FTP サービスで、既定の "Microsoft FTP サービス" バナーを抑制する必要がある場合は true、それ以外の場合は false

既定値は false です。

子要素

なし。

構成サンプル

次の例では、いくつかのカスタマイズされた FTP メッセージをクライアントに返し、既定の FTP バナーを非表示にし、ローカル FTP サーバーにログオンしている FTP クライアントに詳細なエラー メッセージを表示するように FTP サービスを構成する、FTP サイト用の <messages> 要素を示します。

<site name="ftp.example.com" id="5">
  <application path="/">
    <virtualDirectory path="/" physicalPath="c:\inetpub\www.example.com" />
  </application>
  <bindings>
    <binding protocol="ftp" bindingInformation="*:21:" />
  </bindings>
  <ftpServer>
    <messages exitMessage="Goodbye %UserName%!"
      greetingMessage="Hello %UserName%!"
      bannerMessage="This my FTP server."
      suppressDefaultBanner="true"
      allowLocalDetailedErrors="true"
      expandVariables="true" />
    <security>
      <authentication>
        <basicAuthentication enabled="true" />
        <anonymousAuthentication enabled="false" />
      </authentication>
    </security>
  </ftpServer>
</site>

サンプル コード

次の例では、既定のバナーを非表示にし、カスタム バナー メッセージを返すように FTP サイトを構成します。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/sites /[name='ftp.example.com'].ftpServer.messages.bannerMessage:"This is my FTP Server!" /commit:apphost

appcmd.exe set config -section:system.applicationHost/sites /[name='ftp.example.com'].ftpServer.messages.suppressDefaultBanner:"True" /commit:apphost

Note

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

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", @"ftp.example.com");
         if (siteElement == null) throw new InvalidOperationException("Element not found!");
         ConfigurationElement ftpServerElement = siteElement.GetChildElement("ftpServer");

         ConfigurationElement messagesElement = ftpServerElement.GetChildElement("messages");
         messagesElement["bannerMessage"] = @"This is my FTP Server!";
         messagesElement["suppressDefaultBanner"] = 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", "ftp.example.com")
      If (siteElement Is Nothing) Then
         Throw New InvalidOperationException("Element not found!")
      End If
      Dim ftpServerElement As ConfigurationElement = siteElement.GetChildElement("ftpServer")

      Dim messagesElement As ConfigurationElement = ftpServerElement.GetChildElement("messages")
      messagesElement("bannerMessage") = "This is my FTP Server!"
      messagesElement("suppressDefaultBanner") = True

      serverManager.CommitChanges()
   End Sub

   Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray 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
            For i = 0 To keyValues.Length - 1 Step 2
               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
            Next
            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", "ftp.example.com"]);
if (siteElementPos == -1) throw "Element not found!";
var siteElement = sitesCollection.Item(siteElementPos);
var ftpServerElement = siteElement.ChildElements.Item("ftpServer");

var messagesElement = ftpServerElement.ChildElements.Item("messages");
messagesElement.Properties.Item("bannerMessage").Value = "This is my FTP Server!";
messagesElement.Properties.Item("suppressDefaultBanner").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", "ftp.example.com"))
If siteElementPos = -1 Then
   WScript.Echo "Element not found!"
   WScript.Quit
End If
Set siteElement = sitesCollection.Item(siteElementPos)
Set ftpServerElement = siteElement.ChildElements.Item("ftpServer")

Set messagesElement = ftpServerElement.ChildElements.Item("messages")
messagesElement.Properties.Item("bannerMessage").Value = "This is my FTP Server!"
messagesElement.Properties.Item("suppressDefaultBanner").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