FTP 日志记录选项 <log>
概述
<system.ftpServer/log>
元素指定 FTP 服务的全局日志设置。 更具体地说,<system.ftpServer/log>
元素上的属性指定以下选项:
centralLogFileMode
- 此属性指定 FTP 服务是否应使用中央日志记录(每服务器)或站点日志记录(每个站点)。- 指定中央日志记录时,将在单个日志文件中保存所有 FTP 站点的日志。
- 如果指定站点日志记录,每个 FTP 站点将写入单个日志文件。
logInUTF8
- 此属性指定应以 UTF8 格式编码日志文件。
指定中央日志记录时,可以使用 <centralLogFile>
子元素来配置中央日志文件的选项。
兼容性
版本 | 说明 |
---|---|
IIS 10.0 | <log> 元素在 IIS 10.0 中未进行修改。 |
IIS 8.5 | <log> 元素在 IIS 8.5 中未进行修改。 |
IIS 8.0 | <log> 元素在 IIS 8.0 中未进行修改。 |
IIS 7.5 | <system.ftpServer> 元素的 <log> 元素作为 IIS 7.5 的功能提供。 |
IIS 7.0 | <system.ftpServer> 元素的 <log> 元素是在 IIS 7.0 的独立下载项 FTP 7.0 中引入的。 |
IIS 6.0 | <system.ftpServer> 元素及其子元素替换位于 LM/MSFTPSVC 元数据库路径中的 IIS 6.0 FTP 设置。 |
在 Windows 7 和 Windows Server 2008 R2 中,FTP 7.5 服务作为 IIS 7.5 的功能提供,因此无需再下载 FTP 服务。
安装
若要支持 Web 服务器的 FTP 发布,必须安装 FTP 服务。 为此,请按照以下步骤操作。
Windows Server 2012 或 Windows Server 2012 R2
在任务栏上,单击 “服务器管理器”。
在“服务器管理器”中,单击“管理”菜单,然后单击“添加角色和功能”。
在“添加角色和功能”向导中,单击“下一步”。 选择安装类型,然后单击“下一步”。 选择目标服务器,然后单击“下一步”。
在“服务器角色”页上,展开“Web 服务器 (IIS)”,然后选择“FTP 服务器”。
注意
若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS Manager 身份验证,除“FTP 服务”外还需选择“FTP 扩展性”。
。
单击“下一步”,然后在“选择功能”页上,再次单击“下一步”。
在“确认安装选择”页上,单击“安装”。
在“结果” 页面中单击“关闭” 。
Windows 8 或 Windows 8.1
在“开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击“控制面板”。
在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
展开“Internet Information Services”,然后选择“FTP 服务器”。
注意
若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”。
单击“确定”。
单击“关闭” 。
Windows Server 2008 R2
在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。
在“服务器管理器”层次结构窗格中,展开“角色”,然后单击“Web 服务器 (IIS)”。
在“Web 服务器 (IIS)”窗格中,滚动到“角色服务”部分,然后单击“添加角色服务”。
在“添加角色服务向导”的“选择角色服务”页,展开“FTP 服务器”。
选择“FTP 服务”。
注意
若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”。
单击 “下一步” 。
在“确认安装选择”页中,单击“安装”。
在“结果” 页面中单击“关闭” 。
Windows 7
在任务栏上,单击“开始”,然后单击“控制面板”。
在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
展开“Internet Information Services”,然后展开“FTP 服务器”。
选择“FTP 服务”。
注意
若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”。
单击“确定”。
Windows Server 2008 或 Windows Vista
从以下 URL 下载安装包:
按照以下演练中的说明安装 FTP 服务:
操作方式
如何为 FTP 服务配置站点级或服务器级日志记录
打开 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) 管理器”。
在“连接”窗格中,单击服务器名称。
在“主页”窗格中,双击“FTP 日志记录”功能。
在“一个日志文件/每”下拉列表中选择以下选项之一:
- 选择“站点”可指定每个 FTP 站点将写入单个日志文件。
- 选择“服务器”可为所有 FTP 站点指定单个日志文件。
在“操作”窗格中,单击“应用”。
配置
<system.ftpServer/log>
元素在 ApplicationHost.config 中的全局级别配置。
特性
属性 | 说明 | ||||||
---|---|---|---|---|---|---|---|
centralLogFileMode |
可选的枚举属性。 指定 FTP 服务是否应使用中央日志记录(每服务器)或站点日志记录(每个站点)。
Site 。 |
||||||
logInUTF8 |
可选的 Boolean 属性。 指定 IIS 是否应以 UCS 传输格式 8 (UTF-8) 记录 FTP 服务器的所有字符串。 此设置适用于 FTP 服务器上的所有站点的文本模式日志记录。 默认值为 true 。 |
子元素
元素 | 说明 |
---|---|
centralLogFile |
可选元素。 指定中央日志文件的设置。 |
注意
FTP 7.0 架构中声明了一个名为 <customLogging>
的未使用元素,但 FTP 7.5 架构已删除了该属性,因此不得使用。
配置示例
以下配置示例为 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()