共用方式為


預設 FTP 基本驗證設定 < basicAuthentication>

概觀

元素 <basicAuthentication> 會指定基本驗證的設定。 這種形式的驗證要求使用者必須先在伺服器或網域上有效的使用者帳戶,才能登入。

注意

由於檔案傳輸通訊協定的基礎設計 (FTP) ,因此使用者名稱和密碼會以純文字透過 FTP 傳輸,使其容易受到網路探索攻擊。 因此,建議您搭配 SSL 使用基本驗證。

相容性

版本 備註
IIS 10.0 未在 IIS 10.0 中修改專案 <basicAuthentication>
IIS 8.5 未在 IIS 8.5 中修改專案 <basicAuthentication>
IIS 8.0 未在 IIS 8.0 中修改專案 <basicAuthentication>
IIS 7.5 元素 <basicAuthentication><authentication> 元素隨附為 IIS 7.5 的功能。
IIS 7.0 元素 <basicAuthentication><authentication> 元素是在 FTP 7.0 中引進,這是 IIS 7.0 的個別下載專案。
IIS 6.0 元素 <ftpServer> 及其子項目會取代位於 LM/MSFTPSVC 中繼基底路徑中的 IIS 6.0 FTP 設定。

注意

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 擴充性。 .

  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 擴充性。

  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 擴充性。

  6. 按一下 [下一步] 。

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

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

Windows 7

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

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

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

  4. 選取 [FTP 服務]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
    此螢幕擷取畫面顯示針對 Windows 7 選取的 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 驗證 ] 功能。

  4. 在 [ FTP 驗證 ] 頁面上,選取 [基本驗證]。
    顯示 [F T P 驗證] 窗格的螢幕擷取畫面。

  5. 在 [ 動作 ] 窗格中,按一下 [ 啟用 ] 以啟用基本驗證,或按一下 [ 停用 ] 以停用基本驗證。


如何使用 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) 管理員]。
    • 如果您使用 Windows Server 2008 或 Windows Server 2008 R2:

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

      • 在工作列上,按一下 [開始],然後按一下[主控台]。
      • 按兩下 [ 系統管理工具],然後按兩下 [Internet Information Services] ([IIS) 管理員]。
  2. 在 [ 連線 ] 窗格中,按一下樹狀結構中的 [月臺] 節點。

  3. 以滑鼠右鍵按一下樹狀結構中的[月臺]節點,然後按一下 [新增 FTP 站台],或按一下 [動作] 窗格中的 [新增 FTP 站台]。

  4. 當 [ 新增 FTP 站 台精靈] 出現時:

    • [FTP 網站名稱 ] 方塊中輸入 「我的新 FTP 網站」。

    • 針對 [實體路徑 ] 方塊,您可以使用下列其中一個選項來指定內容目錄:

      • 按一下省略號 (...) 按鈕,然後流覽至包含 FTP 網站內容的資料夾。
      • 在方塊中輸入內容資料夾的路徑。 請注意,如果您選擇輸入路徑,您可以在路徑中使用環境變數。 例如,您可以針對內容目錄使用 「%SystemDrive%\inetpub\ftproot」。
    • 當您完成這些專案之後,請按 [下一步]。
      此螢幕擷取畫面顯示 [新增 F T P 月臺] 對話方塊的網站資訊。

  5. [新增 FTP 站 台精靈] 的第二個頁面上:

    • 從 [IP 位址] 下拉式清單中選擇 FTP 網站的 IP 位址 ,或選擇接受 [所有未指派] 的預設選取專案。

    • 在 [ ] 方塊中輸入 FTP 網站的 TCP/IP 埠。 根據預設,FTP 月臺和用戶端會使用埠 21。 (注意:若要指定隱含 FTPS,您必須使用埠 990.)

    • 若要使用 FTP 虛擬主機名稱,請選取 [ 啟用虛擬主機名稱] 的方塊,然後在 [ 虛擬主機 ] 方塊中輸入虛擬主機名稱。

    • 針對 SSL 選項,請選擇下列其中一個選項:

      • 選取 [無 SSL ] 以停用 SSL 選項。
      • 選取 [允許 SSL ] 以允許 FTP 用戶端在與 FTP 伺服器連線時選擇性地使用 FTP over SSL。
      • 選取 [要求 SSL ] 以允許 FTP 用戶端在與 FTP 伺服器連線時一律使用 FTP over SSL。
      • 如果您選擇 [允許 SSL ] 或 [ 需要 SSL],請從 [ SSL 憑證 ] 下拉式功能表中選擇憑證。
    • 當您完成這些專案之後,請按 [下一步]。
      此螢幕擷取畫面顯示 [系結] 和 [S S L 設定] 的 [新增 F T P 月臺] 對話方塊。

  6. 在精靈的下一頁:

    • 針對[驗證設定] 選取 [基本]。
    • 針對 [授權 設定],從 [ 允許存取] 下拉式清單中選擇 [指定使用者],然後在下拉式功能表下方的方塊中輸入帳戶名稱。
    • 針對 [許可權]選項選取[讀取] 和 [寫入]。
    • 當您完成這些專案時,請按一下 [ 完成]。
      顯示驗證和授權資訊的 [新增 F T P 月臺] 對話方塊的螢幕擷取畫面。

組態

屬性

屬性 描述
defaultLogonDomain 選擇性字串屬性。

指定基本驗證使用者帳戶查閱的預設網域。

預設值是 NT AUTHORITY
enabled 選擇性 Boolean 屬性。

指定是否啟用基本驗證。

預設值是 false
logonMethod 選擇性列舉屬性。

指定登入的使用者帳戶登入類型,如 LogonUser WIN32 API 所解譯。
描述
Interactive 指定互動式登入類型。

數值為 0
Batch 指定批次登入類型。

數值為 1
Network 指定網路登入類型。

數值為 2
ClearText 指定純文字登入類型。

數值為 3
預設值是 ClearText

子元素

無。

組態範例

下列組態範例會停用匿名驗證,並預設啟用基本驗證。

<siteDefaults>
   <ftpServer>
      <security>
         <authentication>
            <anonymousAuthentication enabled="false" />
            <basicAuthentication enabled="true" />
         </authentication>
      </security>
   </ftpServer>
</siteDefaults>

範例程式碼

下列程式碼範例會停用匿名驗證,並預設啟用基本驗證。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.ftpServer.security.authentication.anonymousAuthentication.enabled:"False" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.ftpServer.security.authentication.basicAuthentication.enabled:"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");
         ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults");
         ConfigurationElement ftpServerElement = siteDefaultsElement.GetChildElement("ftpServer");

         ConfigurationElement securityElement = ftpServerElement.GetChildElement("security");
         ConfigurationElement authenticationElement = securityElement.GetChildElement("authentication");
         ConfigurationElement anonymousAuthenticationElement = authenticationElement.GetChildElement("anonymousAuthentication");
            anonymousAuthenticationElement["enabled"] = false;
         ConfigurationElement basicAuthenticationElement = authenticationElement.GetChildElement("basicAuthentication");
            basicAuthenticationElement["enabled"] = true;
 
           serverManager.CommitChanges();
      }
   }
}

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 siteDefaultsElement As ConfigurationElement = sitesSection.GetChildElement("siteDefaults")
      Dim ftpServerElement As ConfigurationElement = siteDefaultsElement.GetChildElement("ftpServer")

      Dim securityElement As ConfigurationElement = ftpServerElement.GetChildElement("security")
      Dim authenticationElement As ConfigurationElement = securityElement.GetChildElement("authentication")
      Dim anonymousAuthenticationElement As ConfigurationElement = authenticationElement.GetChildElement("anonymousAuthentication")
         anonymousAuthenticationElement("enabled") = False
      Dim basicAuthenticationElement As ConfigurationElement = authenticationElement.GetChildElement("basicAuthentication")
         basicAuthenticationElement("enabled") = True

      serverManager.CommitChanges()
   End Sub

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 siteDefaultsElement = sitesSection.ChildElements.Item("siteDefaults");
var ftpServerElement = siteDefaultsElement.ChildElements.Item("ftpServer");

var securityElement = ftpServerElement.ChildElements.Item("security");
var authenticationElement = securityElement.ChildElements.Item("authentication");
var anonymousAuthenticationElement = authenticationElement.ChildElements.Item("anonymousAuthentication");
   anonymousAuthenticationElement.Properties.Item("enabled").Value = false;
var basicAuthenticationElement = authenticationElement.ChildElements.Item("basicAuthentication");
   basicAuthenticationElement.Properties.Item("enabled").Value = true;

adminManager.CommitChanges();

VBScript

Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")
Set siteDefaultsElement = sitesSection.ChildElements.Item("siteDefaults")
Set ftpServerElement = siteDefaultsElement.ChildElements.Item("ftpServer")

Set securityElement = ftpServerElement.ChildElements.Item("security")
Set authenticationElement = securityElement.ChildElements.Item("authentication")
Set anonymousAuthenticationElement = authenticationElement.ChildElements.Item("anonymousAuthentication")
   anonymousAuthenticationElement.Properties.Item("enabled").Value = False
Set basicAuthenticationElement = authenticationElement.ChildElements.Item("basicAuthentication")
   basicAuthenticationElement.Properties.Item("enabled").Value = true

adminManager.CommitChanges()