FTP 中央日志记录选项 <centralLogFile>

概述

<centralLogFile> 元素指定中央日志文件的设置,在为 <system.ftpServer/log> 元素的 centralLogFileMode 属性指定 centralLogFileMode 时会使用此文件。 指定中央日志记录时,将在单个日志文件中保存所有 FTP 站点的日志。

兼容性

版本 说明
IIS 10.0 <centralLogFile> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <centralLogFile> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <centralLogFile> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <log> 元素的 <centralLogFile> 元素作为 IIS 7.5 的功能提供。
IIS 7.0 <log> 元素的 <centralLogFile> 元素是在 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 Manager 身份验证,除“FTP 服务”外还需选择“FTP 扩展性”
    Image of Web Server I I S and F T P Server in Server Roles page expanded and F T P Server highlighted.

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

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

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

Windows 8 或 Windows 8.1

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

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

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

    注意

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

  4. 单击“确定”。

  5. 单击“关闭” 。

Windows Server 2008 R2

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

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

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

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

  5. 选择“FTP 服务”。

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”
    Screenshot of F T P Service selected from F T P Server pane in Select Role Services page of the Add Role Services Wizard.

  6. 单击 “下一步”

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

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

Windows 7

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

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

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

  4. 选择“FTP 服务”。

    注意

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

  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 Home pane with F T P Logging selected.

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

    • 选择“站点”可指定每个 FTP 站点将写入单个日志文件。
    • 选择“服务器”可为所有 FTP 站点指定单个日志文件。
      Screenshot of F T P Logging displaying Site chosen from One log file per drop down list and log file drop down menu.
  5. 在“操作”窗格中,单击“应用”

配置

<centralLogFile> 元素在 ApplicationHost.config 中的全局级别配置。

属性 说明
directory 可选的字符串属性。

指定日志记录目录,其中存储日志文件和与日志记录相关的支持文件。

默认值为 %SystemDrive%\inetpub\logs\LogFiles
enabled 可选的 Boolean 属性。

如果启用了日志记录,则为 true;否则为 false

默认值为 true
localTimeRollover 可选的 Boolean 属性。

如果基于本地时间创建新日志文件,则为 true;否则,基于协调世界时 (UTC)(以前称为格林威治标准时间 (GMT))创建则为 false

注意:无论设置如何,每个 W3C 扩展日志记录的时间戳都是基于 UTC 的

默认值为 false
logExtFileFlags 可选 flags 属性。

指定在记录站点事件期间写入日志文件(使用 W3C 扩展日志文件格式时)或 ODBC 数据源的信息类别。 logExtFileFlags 属性可为以下一个或多个值。 如果指定多个值,请用逗号 (,) 分隔。

默认值为 DateTimeClientIPUserNameServerIPMethodUriStemFtpStatusWin32StatusFtpSubStatusServerPortSessionFullPath
说明
BytesRecv 记录服务器接收的字节数。

数值为 8192
BytesSent 记录服务器发送的字节数。

数值为 4096
ClientIP 记录发出请求的客户端的 IP 地址。

数值为 4
ClientPort 记录发出请求的客户端的端口。

数值为 33554432
ComputerName 记录在其上生成日志文件条目的服务器的名称。

数值为 32
Date 记录活动的发生日期。

数值为 1
FtpStatus 记录 FTP 状态代码。

数值为 1024
FtpSubStatus 记录 FTP 错误的子状态代码。

数值为 2097152
FullPath 记录完整的相对路径。 注意:这可能不同与客户端请求的 URI,通过设置 UriStem 标志可记录后者。

数值为 8388608
Host 记录虚拟主机名(如有)。

数值为 1048576
Info 记录扩展调试信息(如有)。

数值为 16777216
Method 记录请求的操作。 例如 USER、PASS 等

数值为 128
ServerIP 记录在其上生成日志文件条目的服务器的 IP 地址。

数值为 64
ServerPort 记录为站点配置的服务器端口号。

数值为 32768
Session 记录 FTP 会话的唯一标识符。 这对于分析日志中的会话活动非常有用。

数值为 4194304
SiteName 记录站点的 Internet 服务名称和实例编号。

数值为 16
Time 记录活动发生的时间,采用协调世界时 (UTC)。

数值为 2
TimeTaken 记录完成请求所用的时间。 所用时间以毫秒为单位记录。

数值为 16384
UriStem 记录通用资源标识符 (URI) 干信息,该信息是操作的目标。 注意:这显示的 URI 资源与客户端请求的完全一样,可能不是完整的相对路径。 对于完整的相对路径,请使用 FullPath 标志。

数值为 256
UserName 记录访问服务器的经过身份验证的用户的名称。 匿名用户会以连字符表示。

数值为 8
Win32Status 记录 Windows 状态代码。

数值为 2048
period 可选的枚举属性。

指定 FTP 服务创建新日志文件的频率。 period 属性可为以下值之一。

默认值为 Daily
说明
Daily 每天创建一个新日志文件。

数值为 1
Hourly 每小时创建一个新日志文件。

数值为 4
MaxSize 达到最大大小时创建一个新日志文件。 truncateSize 属性中指定了最大大小。

数值为 0
Monthly 每月创建一个新日志文件。

数值为 3
Weekly 每周创建一个新日志文件。

数值为 2
selectiveLogging 可选 flags 属性。

指定 FTP 日志记录的详细程度。

默认值为 LogSuccessful,LogError,LogInfrastructure
说明
LogError 指定将记录错误。 实际记录的数据量也取决于 LogInfrastructure 标志的设置。

数值为 2
LogInfrastructure 指定将记录所有 FTP 命令和低级别数据信道活动。 例如,如果设置了 LogInfrastructure 标志,日志将包含 DataChannelOpened、DataChannelClosed、PORT/EPRT 和 PASV/EPSV 的条目。

数值为 4
LogSuccessful 指定将记录成功的活动。 实际记录的数据量也取决于 LogInfrastructure 标志的设置。

数值为 1
truncateSize 可选 int64 属性。

指定日志文件的最大大小(以字节为单位),超过该大小后将创建新日志文件。 仅当为 period 属性选择了 MaxSize 时,此值才适用。 最小文件大小是 1,048,576 字节。 如果将此特性设置为小于 1048576 个字节的值,则会隐式将默认值假定为 1048576 个字节。

默认值为 20971520

子元素

无。

配置示例

以下配置示例为 FTP 服务启用中央文件日志记录。

<system.ftpServer>
   <log centralLogFileMode="Central">
      <centralLogFile enabled="true" />
   </log>
</system.ftpServer>

代码示例

以下示例为 FTP 服务启用中央文件日志记录。

AppCmd.exe

appcmd.exe set config -section:system.ftpServer/log /centralLogFileMode:"Central" /commit:apphost

appcmd.exe set config -section:system.ftpServer/log /centralLogFile.enabled:"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 logSection = config.GetSection("system.ftpServer/log");
         logSection["centralLogFileMode"] = @"Central";

         ConfigurationElement centralLogFileElement = logSection.GetChildElement("centralLogFile");
         centralLogFileElement["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 logSection As ConfigurationSection = config.GetSection("system.ftpServer/log")
      logSection("centralLogFileMode") = "Central"

      Dim centralLogFileElement As ConfigurationElement = logSection.GetChildElement("centralLogFile")
      centralLogFileElement("enabled") = True

      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

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

var logSection = adminManager.GetAdminSection("system.ftpServer/log", "MACHINE/WEBROOT/APPHOST");
logSection.Properties.Item("centralLogFileMode").Value = "Central";

var centralLogFileElement = logSection.ChildElements.Item("centralLogFile");
centralLogFileElement.Properties.Item("enabled").Value = true;

adminManager.CommitChanges();

VBScript

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

Set logSection = adminManager.GetAdminSection("system.ftpServer/log", "MACHINE/WEBROOT/APPHOST")
logSection.Properties.Item("centralLogFileMode").Value = "Central"

Set centralLogFileElement = logSection.ChildElements.Item("centralLogFile")
centralLogFileElement.Properties.Item("enabled").Value = True

adminManager.CommitChanges()