默认 FTP 连接设置 <connections>

概述

<connections> 元素指定 FTP 站点的连接相关设置。 更具体地说,<connections> 元素中的设置控制 FTP 服务有关如何管理连接到 FTP 站点的客户端的行为。

例如,unauthenticatedTimeoutcontrolChannelTimeoutdataChannelTimeout 属性指定 FTP 站点的超时。 这些设置分别指定 FTP 服务何时断开未成功登录或处于空闲状态的 FTP 客户端的连接,或者何时断开空闲数据连接的连接。 为 <connections> 元素中的属性指定值可能会直接影响服务器的整体性能,因为这可帮助控制 FTP 站点的活动客户端会话数。

兼容性

版本 说明
IIS 10.0 <connections> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <connections> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <connections> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <ftpServer> 元素的 <connections> 元素作为 IIS 7.5 的功能提供。
IIS 7.0 <ftpServer> 元素的 <connections> 元素是在 IIS 7.0 的独立下载项 FTP 7.0 中引入的。
IIS 6.0 空值

注意

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 the Server Roles page. Web Server I I S is expanded. F T P Server is expanded. F T P Extensibility is highlighted and selected. .

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

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

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

Windows 8 或 Windows 8.1

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

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

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

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”
    Screenshot of the navigation tree. F T P Server is expanded. The F T P Extensibility folder is highlighted and selected.

  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 Select Role Services Page. F T P Server is expanded. F T P Service is highlighted and selected.

  6. 单击 “下一步”

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

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

Windows 7

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

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

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

  4. 选择“FTP 服务”

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”
    Screenshot of the Programs and Features navigation tree. F T P Service is selected.

  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 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 站点默认值...”

  4. 在“高级设置”对话框中,展开“连接”,在“控制通道超时”和“数据信道超时”字段中指定超时时间,然后单击“确定”

配置

特性

属性 说明
controlChannelTimeout 可选 int 属性。

指定因控制通道上未发生活动而导致连接超时的时间(以秒为单位)。 注意:达到超时时,FTP 服务会断开会话的连接。

默认值为 120
dataChannelTimeout 可选 int 属性。

指定因数据信道上未发生活动而导致连接超时的时间(以秒为单位)。 注意:FTP 服务仅在达到此超时时断开数据信道的连接。

默认值为 30
disableSocketPooling 可选的 Boolean 属性。 如果禁用套接字池,则为 true;否则为 falsedisableSocketPooling 属性指定套接字池是否用于通过 IP 地址而不是端口号或主机名区分的站点。 如果 disableSocketPooling 设置为 false,则启用套接字池,并在使用相同套接字编号但 IP 地址不同的站点之间共享套接字。 在这种情况下,FTP 服务将成为绑定到服务器上每个地址的端口的独占所有者。 例如,如果在具有两个 IP 地址(10.0.0.1 和 10.0.0.2)的服务器上启用了套接字池,并且 FTP 站点绑定到地址 10.0.0.1 的端口 21 上,则 FTP 服务还将拥有 10.0.0.2 地址上的端口 21。 如果 disableSocketPooling 设置为 true,则基于 IP 地址的站点不会共享套接字。 默认值为 false
maxBandwidth 未使用的 uint 属性。

注意:FTP 7 未实现此属性。
maxConnections 可选 unit 属性。

指定 FTP 站点的最大同时连接数。

注意:使用 <messages> 元素的 maxClientsMessage 属性可指定当超过最大同时连接数时 FTP 服务将返回到客户端的消息。

默认值为 4294967295(无限制)。
minBytesPerSecond 可选 int 属性。

指定数据传输的最低带宽要求。 注意:如果未满足最低带宽要求,FTP 服务将断开数据信道的连接。

默认值为 240
resetOnMaxConnections 可选的 Boolean 属性。

如果 FTP 服务应快速断开 FTP 会话的连接,而不是发送最大连接数响应,则为 true;否则为 false

注意:resetOnMaxConnections 属性可优化因达到 maxConnection 限制而不允许连接的连接时的开销

默认值为 false
serverListenBacklog 可选 int 属性。

指定可排队的未处理套接字的数目。

默认值为 60
unauthenticatedTimeout 可选 int 属性。

指定建立新连接与身份验证成功之间的空闲超时值(以秒为单位)。 如果客户端未在指定的时间段内成功进行身份验证,FTP 服务将断开会话的连接。

默认值为 30

子元素

无。

配置示例

以下配置示例显示了默认控制通道超时设置为 300 秒的服务器的示例 <connections> 元素。

<siteDefaults>
   <ftpServer>
      <connections controlChannelTimeout="300" />
   </ftpServer>
</siteDefaults>

代码示例

以下代码示例演示了如何将默认控制通道超时设置为 300 秒。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.ftpServer.connections.controlChannelTimeout:"300" /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 sitesSection = config.GetSection("system.applicationHost/sites");
         ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults");
         ConfigurationElement ftpServerElement = siteDefaultsElement.GetChildElement("ftpServer");

         ConfigurationElement connectionsElement = ftpServerElement.GetChildElement("connections");
         connectionsElement["controlChannelTimeout"] = 300;

         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 connectionsElement As ConfigurationElement = ftpServerElement.GetChildElement("connections")
      connectionsElement("controlChannelTimeout") = 300

      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 connectionsElement = ftpServerElement.ChildElements.Item("connections");
connectionsElement.Properties.Item("controlChannelTimeout").Value = 300;

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 connectionsElement = ftpServerElement.ChildElements.Item("connections")
connectionsElement.Properties.Item("controlChannelTimeout").Value = 300

adminManager.CommitChanges()