共用方式為


FTP 訊息訊息 <>

概觀

元素 <messages> 是用來指定 FTP 服務會顯示給 FTP 用戶端的訊息。 當 FTP 用戶端連線到 FTP 網站時,會顯示為 bannerMessagegreetingMessagemaxClientsMessage 屬性指定的訊息,而當 FTP 用戶端與 FTP 月臺中斷連線時,就會顯示 屬性所 exitMessage 指定的訊息。

屬性 suppressDefaultBanner 可以與 屬性搭配 bannerMessage 使用,以區分您的 FTP 伺服器類型。 如果隱藏預設橫幅,而且屬性中 bannerMessage 未指定橫幅訊息,FTP 伺服器會在 FTP 用戶端連線到您的伺服器時顯示空白橫幅。

屬性 expandVariables 會指定是否要在 FTP 訊息中顯示一組特定的使用者變數。 如果此屬性設定為 true,FTP 服務會在 FTP 訊息中顯示使用者變數;否則,所有郵件內文都會顯示為輸入。 支援的使用者變數如下:

User 變數 描述
%BytesReceived% 從伺服器傳送至目前會話之用戶端的位元組數目。
%BytesSent% 從用戶端傳送到伺服器目前會話的位元組數目。
%SessionID% 目前會話的唯一識別碼。
%SiteName% 裝載目前會話的 FTP 月臺名稱。
%UserName% 目前登入使用者的帳戶名稱。

屬性 allowLocalDetailedErrors 會指定當 FTP 用戶端連接到伺服器本身上的 FTP 伺服器時,是否要顯示詳細的錯誤訊息。 這些錯誤訊息包含伺服器系統管理員可用來針對問題進行疑難排解的詳細資訊。 如果此屬性設定為 true,FTP 服務只會向本機主機顯示詳細的錯誤訊息;否則,不會顯示詳細的錯誤訊息。

相容性

版本 備註
IIS 10.0 未在 IIS 10.0 中修改專案 <messages>
IIS 8.5 未在 IIS 8.5 中修改專案 <messages>
IIS 8.0 未在 IIS 8.0 中修改專案 <messages>
IIS 7.5 元素 <messages><ftpServer> 元素隨附為 IIS 7.5 的功能。
IIS 7.0 元素 <messages><ftpServer> 元素是在 FTP 7.0 中引進,這是 IIS 7.0 的個別下載專案。
IIS 6.0 N/A

注意

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 伺服器]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,除了FTP 服務之外,您還需要選取[FTP 擴充性]。
    在 Windows Server 2012 介面中選取的 F T P 服務和 F T P 擴充性螢幕擷取畫面。 .

  5. [下一步],然後在 [ 選取功能 ] 頁面上,再次按 [ 下一步 ]。

  6. 在 [確認安裝選項] 頁面上,按一下 [安裝]

  7. 在 [結果] 頁面上,按一下 [關閉]

Windows 8 或 Windows 8.1

  1. 在 [開始] 畫面上,將指標一路移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。

  2. 主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。

  3. 展開 [Internet Information Services],然後選取 [ FTP 伺服器]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
    在 Windows 8 介面中選取的 F T P 服務和 F T P 擴充性螢幕擷取畫面。

  4. 按一下 [確定]。

  5. 按一下 [關閉] 。

Windows Server 2008 R2

  1. 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。

  2. [伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS)

  3. 在 [ Web Server (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。

  4. 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,展開[FTP 伺服器]。

  5. 選取 [FTP 服務]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
    在 Windows Server 2008 介面中選取的 F T P 服務和 F T P 擴充性螢幕擷取畫面。

  6. 按一下 [下一步] 。

  7. 在 [確認安裝選項] 頁面上,按一下 [安裝]

  8. 在 [結果] 頁面上,按一下 [關閉]

Windows 7

  1. 在工作列上,按一下 [開始],然後按一下[主控台]。

  2. 主控台中,按一下 [程式和功能],然後按一下[開啟或關閉 Windows 功能]。

  3. 展開 [Internet Information Services],然後展開 [ FTP 伺服器]。

  4. 選取 [FTP 服務]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
    在 Windows 7 介面中選取的 F T P 服務和 F T P 擴充性螢幕擷取畫面。

  5. 按一下 [確定]。

Windows Server 2008 或 Windows Vista

  1. 從下列 URL 下載安裝套件:

  2. 請遵循下列逐步解說中的指示來安裝 FTP 服務:

作法

如何設定 FTP 網站的自訂訊息

  1. 開啟 [Internet Information Services (IIS) 管理員

    • 如果您使用 Windows Server 2012 或 Windows Server 2012 R2:

      • 在工作列上,依序按一下 [伺服器管理員]、[工具],然後按一下 [Internet Information Services (IIS) Manager]。
    • 如果您使用 Windows 8 或 Windows 8.1:

      • 按住Windows鍵,按字母X,然後按一下[主控台]。
      • 按一下 [系統管理工具],然後按兩下 [ Internet Information Services (IIS) Manager]。
    • 如果您使用 Windows Server 2008 或 Windows Server 2008 R2:

      • 在工作列上,按一下 [ 開始],指向 [ 系統管理工具],然後按一下 [ Internet Information Services (IIS) 管理員]。
    • 如果您使用 Windows Vista 或 Windows 7:

      • 在工作列上,按一下 [開始],然後按一下[主控台]。
      • 按兩下 [系統管理工具],然後按兩下 [ Internet Information Services] (IIS) Manager
  2. 在 [ 連線] 窗格中,展開伺服器名稱、展開 [ 台] 節點,然後按一下網站的名稱。

  3. 在網站的 [ 首頁 ] 窗格中,按兩下 [FTP 訊息] 功能。
    網站 [首頁] 窗格中所選取 F T P 訊息選項的螢幕擷取畫面。

  4. 設定下列選項:

    • 按一下以選取 [ 隱藏預設橫幅 ] 選項。
    • 按一下即可選取 [訊息中的支援使用者變數 ] 選項。
    • 輸入 橫幅訊息的 「這是我的 FTP 伺服器」。
    • 輸入 歡迎訊息的 「Hello %UserName%!」 。
    • Exit 訊息中輸入 「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 Service」 橫幅,則為true;否則為false

預設值是 false

子元素

無。

組態範例

下列範例會顯示 FTP 月臺的 元素,該月臺會設定 FTP 服務將數個 <messages> 自訂 FTP 訊息傳回給用戶端、隱藏預設 FTP 橫幅,以及向登入本機 FTP 伺服器的 FTP 用戶端顯示詳細的錯誤訊息。

<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

注意

當您使用 AppCmd.exe 來設定這些設定時,請務必將 認可 參數 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