<system.ftpServer>

概述

<system.ftpServer> 元素在 ApplicationHost.config 文件中指定 FTP 7 的全局级别和 URL 级配置设置,并包含定义 FTP 服务所使用的设置的配置元素。

注意

与在 <system.webServer> 中找到的设置不同,<system.ftpServer> 元素中的设置无法委托。

兼容性

版本 说明
IIS 10.0 <system.ftpServer> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <system.ftpServer> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <system.ftpServer> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <system.ftpServer> 元素作为 IIS 7.5 的功能提供。
IIS 7.0 <system.ftpServer> 元素是在 IIS 7.0 的独立下载项 FTP 7.0 中引入的。
IIS 6.0 <system.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 服务器”

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,除“FTP 服务”外还需选择“FTP 扩展性”

    Screenshot of Roles menu expanded. F T P Extensibility is highlighted. .

  5. 单击“下一步”,然后在“选择功能”页上,再次单击“下一步”。

  6. “确认安装选择”页上,单击“安装”

  7. 在“结果” 页面中单击“关闭”

Windows 8 或 Windows 8.1

  1. 在“开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击“控制面板”

  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。

  3. 展开“Internet Information Services”,然后选择“FTP 服务器”

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”

    Screenshot of Windows Features dialog box with F T P Extensibility highlighted in the expanded menu.

  4. 单击“确定”。

  5. 单击“关闭” 。

Windows Server 2008 R2

  1. 在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。

  2. 在“服务器管理器”层次结构窗格中,展开“角色”,然后单击“Web 服务器 (IIS)”。

  3. 在“Web 服务器 (IIS)”窗格中,滚动到“角色服务”部分,然后单击“添加角色服务”。

  4. 在“添加角色服务向导”的“选择角色服务”页,展开“FTP 服务器”。

  5. 选择“FTP 服务”。

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”

    Screenshot of the Add Role Services page with F T P Service highlighted in the expanded menu.

  6. 单击 “下一步”

  7. “确认安装选择”页中,单击“安装”

  8. 在“结果” 页面中单击“关闭”

Windows 7

  1. 在任务栏上,单击“开始”,然后单击“控制面板”。

  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。

  3. 展开“Internet Information Services”,然后展开“FTP 服务器”

  4. 选择“FTP 服务”。

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”

    Screenshot of Windows Features dialog box with the o k button highlighted.

  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)管理器”
    • 如果使用的是 Windows 8 或 Windows 8.1:

      • 按住 Windows 键,按字母 X,然后单击“控制面板”。
      • 单击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
    • 如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:

      • 在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”
    • 如果使用的是 Windows Vista 或 Windows 7:

      • 在任务栏上,单击“开始”,然后单击“控制面板”。
      • 双击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
  2. 在“连接”窗格中,单击服务器名称

  3. 在“主页”窗格中,双击“FTP 日志记录”功能
    Screenshot of the I I S Manager Home pane. The F T P Logging feature is highlighted.

  4. 在“一个日志文件/每”下拉列表中选择以下选项之一:

    • 选择“站点”可指定每个 FTP 站点将写入单个日志文件。
    • 选择“服务器”可为所有 FTP 站点指定单个日志文件。
      Screenshot of the I I S Manager F T P Logging tab.
  5. 在“操作”窗格中,单击“应用”

配置

可以在全局级别、站点级别和每个 URL 上配置 <system.ftpServer> 元素中的设置。

特性

无。

子元素

元素 说明
log 可选元素。

指定 FTP 服务的全局日志设置。
firewallSupport 可选元素。

指定 FTP 服务将用于数据通道通信的端口范围。
providerDefinitions 可选元素。

指定自定义 FTP 提供程序的集合。
security 可选元素。

指定 FTP 的安全相关设置。
caching 可选元素。

指定 FTP 服务的凭据缓存设置。
serverRuntime 可选元素。

指定配置 FTP 服务操作方式的设置。

配置示例

下面的示例演示了服务器的全局 <system.ftpServer> 元素中的若干配置设置。 更具体而言,此示例中的设置演示如何:

  • 启用 FTP 凭据缓存,并指定超时值为 10 分钟(600 秒)。

  • 对于数据通道通信,将低端口配置为 5000,高端口配置为 6000。

  • 启用日志记录,指定须按站点保留日志文件,并按 UTC 时间每天轮换日志文件。

  • 指定自定义 FTP 提供程序,并为该提供程序指定自定义参数。

  • 指定全局 IP 限制,以允许从本地主机进行 FTP 访问,并拒绝 IP 地址块 169.254.0.0 到 169.254.255.255 的访问。

  • 使用以下选项配置请求筛选:

    • 阻止 FTP 访问 _vti_bin 虚拟目录,此目录与 FrontPage 服务器扩展一起使用。
    • 阻止与可执行文件关联的多个文件类型。
    • 指定最大文件大小为 100MB。
  • 添加一个全局授权规则,用于为管理员组授予访问权限。

  • 指明可以将域名语法用于 FTP 虚拟主机名。

<system.ftpServer>
   <caching>
      <credentialsCache enabled="true" flushInterval="600" />
   </caching>
   <firewallSupport lowDataChannelPort="5000" highDataChannelPort="6000" />
   <log centralLogFileMode="Site">
      <centralLogFile period="Daily" localTimeRollover="false" enabled="true" />
   </log>
   <providerDefinitions>
      <add name="FtpXmlAuthentication"
         type="FtpXmlAuthentication, FtpXmlAuthentication, version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73" />
      <activation>
         <providerData name="FtpXmlAuthentication">
            <add key="xmlFileName" value="C:\Inetpub\XmlSample\Users.xml" />
         </providerData>
      </activation>
   </providerDefinitions>
   <security>
      <ipSecurity enableReverseDns="false" allowUnlisted="true">
         <add ipAddress="169.254.0.0" subnetMask="255.255.0.0" allowed="false" />
         <add ipAddress="127.0.0.1" allowed="true" />
      </ipSecurity>
      <requestFiltering>
         <hiddenSegments>
            <add segment="_vti_bin" />
         </hiddenSegments>
         <fileExtensions allowUnlisted="true">
            <add fileExtension="exe" allowed="false" />
            <add fileExtension="cmd" allowed="false" />
            <add fileExtension="com" allowed="false" />
            <add fileExtension="bat" allowed="false" />
         </fileExtensions>
         <requestLimits maxAllowedContentLength="104857600" />
      </requestFiltering>
      <authorization>
         <add accessType="Allow" roles="administrators" permissions="Read, Write" />
      </authorization>
   </security>
   <serverRuntime>
      <hostNameSupport useDomainNameAsHostName="true" />
   </serverRuntime>
</system.ftpServer>

代码示例

以下示例为默认网站添加两个 FTP 授权规则。 第一个规则允许管理员组具有读取和写入访问权限,第二个规则拒绝来宾帐户的读取和写入访问权限。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.ftpServer/security/authorization /+"[accessType='Allow',roles='administrators',permissions='Read, Write']" /commit:apphost

appcmd.exe set config "Default Web Site" -section:system.ftpServer/security/authorization /+"[accessType='Deny',users='guest',permissions='Read, Write']" /commit:apphost

注意

使用 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 authorizationSection = config.GetSection("system.ftpServer/security/authorization", "Default Web Site");
         ConfigurationElementCollection authorizationCollection = authorizationSection.GetCollection();

         ConfigurationElement addElement = authorizationCollection.CreateElement("add");
         addElement["accessType"] = @"Allow";
         addElement["roles"] = @"administrators";
         addElement["permissions"] = @"Read, Write";
         authorizationCollection.Add(addElement);

         ConfigurationElement addElement1 = authorizationCollection.CreateElement("add");
         addElement1["accessType"] = @"Deny";
         addElement1["users"] = @"guest";
         addElement1["permissions"] = @"Read, Write";
         authorizationCollection.Add(addElement1);

         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 authorizationSection As ConfigurationSection = config.GetSection("system.ftpServer/security/authorization", "Default Web Site")
      Dim authorizationCollection As ConfigurationElementCollection = authorizationSection.GetCollection

      Dim addElement As ConfigurationElement = authorizationCollection.CreateElement("add")
      addElement("accessType") = "Allow"
      addElement("roles") = "administrators"
      addElement("permissions") = "Read, Write"
      authorizationCollection.Add(addElement)

      Dim addElement1 As ConfigurationElement = authorizationCollection.CreateElement("add")
      addElement1("accessType") = "Deny"
      addElement1("users") = "guest"
      addElement1("permissions") = "Read, Write"
      authorizationCollection.Add(addElement1)

      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var authorizationSection = adminManager.GetAdminSection("system.ftpServer/security/authorization", "MACHINE/WEBROOT/APPHOST/Default Web Site");
var authorizationCollection = authorizationSection.Collection;

var addElement = authorizationCollection.CreateNewElement("add");
addElement.Properties.Item("accessType").Value = "Allow";
addElement.Properties.Item("roles").Value = "administrators";
addElement.Properties.Item("permissions").Value = "Read, Write";
authorizationCollection.AddElement(addElement);

var addElement1 = authorizationCollection.CreateNewElement("add");
addElement1.Properties.Item("accessType").Value = "Deny";
addElement1.Properties.Item("users").Value = "guest";
addElement1.Properties.Item("permissions").Value = "Read, Write";
authorizationCollection.AddElement(addElement1);

adminManager.CommitChanges();

VBScript

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

Set authorizationSection = adminManager.GetAdminSection("system.ftpServer/security/authorization", "MACHINE/WEBROOT/APPHOST/Default Web Site")
Set authorizationCollection = authorizationSection.Collection

Set addElement = authorizationCollection.CreateNewElement("add")
addElement.Properties.Item("accessType").Value = "Allow"
addElement.Properties.Item("roles").Value = "administrators"
addElement.Properties.Item("permissions").Value = "Read, Write"
authorizationCollection.AddElement(addElement)

Set addElement1 = authorizationCollection.CreateNewElement("add")
addElement1.Properties.Item("accessType").Value = "Deny"
addElement1.Properties.Item("users").Value = "guest"
addElement1.Properties.Item("permissions").Value = "Read, Write"
authorizationCollection.AddElement(addElement1)

adminManager.CommitChanges()

以下示例配置 FTP 服务器的 <serverRuntime> 元素,以允许 FTP 虚拟主机名的域名语法。

AppCmd.exe

appcmd.exe set config -section:system.ftpServer/serverRuntime /hostNameSupport.useDomainNameAsHostName:"True" /commit:apphost

注意

使用 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 serverRuntimeSection = config.GetSection("system.ftpServer/serverRuntime");

         ConfigurationElement hostNameSupportElement = serverRuntimeSection.GetChildElement("hostNameSupport");
         hostNameSupportElement["useDomainNameAsHostName"] = 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 serverRuntimeSection As ConfigurationSection = config.GetSection("system.ftpServer/serverRuntime")

      Dim hostNameSupportElement As ConfigurationElement = serverRuntimeSection.GetChildElement("hostNameSupport")
      hostNameSupportElement("useDomainNameAsHostName") = True

      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

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

var serverRuntimeSection = adminManager.GetAdminSection("system.ftpServer/serverRuntime", "MACHINE/WEBROOT/APPHOST");
var hostNameSupportElement = serverRuntimeSection.ChildElements.Item("hostNameSupport");
hostNameSupportElement.Properties.Item("useDomainNameAsHostName").Value = true;

adminManager.CommitChanges();

VBScript

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

Set serverRuntimeSection = adminManager.GetAdminSection("system.ftpServer/serverRuntime", "MACHINE/WEBROOT/APPHOST")
Set hostNameSupportElement = serverRuntimeSection.ChildElements.Item("hostNameSupport")
hostNameSupportElement.Properties.Item("useDomainNameAsHostName").Value = True

adminManager.CommitChanges()