概要
<logFile>
要素は、FTP サイトのアクティビティ ログ オプションを構成するために使用されます。
たとえば、ログの有効化や無効化、ログ ファイルに格納する情報のカテゴリの指定、ログ ファイルが格納されるディレクトリの変更を実行できます。 <logFile>
要素は、ログ ファイルのサイズと期間のいずれかに基づいて IIS が新しいログ ファイルを作成する頻度と、ログ ファイルが到達可能な最大サイズ (バイト) の制御にも使用できます。
Note
ログ ファイルに IIS、NCSA、または W3C の各形式を使用できる Web サイトとは異なり、FTP 7 サービスはログ ファイルを W3C 形式にのみ格納します。
logExtFileFlags 属性を編集して、IIS がログに記録する情報のカテゴリを定義できます。 既定値は、Date
、Time
、ClientIP
、UserName
、ServerIP
、Method
、UriStem
、FtpStatus
、Win32Status
、FtpSubStatus
、ServerPort
、Session
、および FullPath
です。
互換性
バージョン | メモ |
---|---|
IIS 10.0 | <logFile> 要素は IIS 10.0 では変更されませんでした。 |
IIS 8.5 | <logFile> 要素は IIS 8.5 では変更されませんでした。 |
IIS 8.0 | <logFile> 要素は IIS 8.0 では変更されませんでした。 |
IIS 7.5 | <ftpServer> 要素の <logFile> 要素は、IIS 7.5 の機能として付属しています。 |
IIS 7.0 | <ftpServer> 要素の <logFile> 要素が、IIS 7.0 用の別個のダウンロードとして FTP 7.0 で導入されました。 |
IIS 6.0 | 該当なし |
Note
FTP 7.0 サービスと FTP 7.5 サービスは IIS 7.0 とは別に出荷され、次の URL からモジュールをダウンロードしてインストールする必要がありました。
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 サーバー] を選びます。
[次へ] をクリックし、[機能の選択] ページで再度 [次へ] をクリックします。
[インストール オプションの確認] ページで、[インストール] をクリックします。
[結果] ページで、 [閉じる]をクリックします。
Windows 8 または Windows 8.1
[スタート] 画面で、ポインターを左下隅まで移動し、[スタート] ボタンを右クリックし、[コントロール パネル] をクリックします。
[コントロール パネル]で [プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。
[インターネット インフォメーション サービス] を展開し、[FTP サーバー] を展開します。
OK をクリックします。
閉じるをクリックします。
Windows Server 2008 R2
タスク バーで [スタート] をクリックし、[管理ツール] をポイントして、[サーバー マネージャ] をクリックします。
[サーバー マネージャ] 階層ウィンドウで [役割] を展開し、[Web サーバー (IIS)] をクリックします。
[Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールし、[役割サービスの追加] をクリックします。
[役割サービスの追加] ウィザードの [役割サービスの選択] ページで [FTP サーバー] を展開します。
[FTP Service] を選択します。
次へ をクリックします。
[インストール オプションの確認] ページで、[インストール] をクリックします。
[結果] ページで、 [閉じる]をクリックします。
Windows 7
タスク バーで、[スタート]、[コントロール パネル] の順にクリックします。
[コントロール パネル]で [プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。
[インターネット インフォメーション サービス]、[FTP サーバー] の順に展開します。
[FTP Service] を選択します。
OK をクリックします。
Windows Server 2008 または Windows Vista
次の URL からインストール パッケージをダウンロードします。
次のチュートリアルの手順に従って、FTP サービスをインストールします。
操作方法
FTP サイトのログ オプションを構成する方法
インターネット インフォメーション サービス (IIS) マネージャーを開きます。
Windows Server 2012 または Windows Server 2012 R2 を使用している場合:
- タスク バーで、[サーバー マネージャー] をクリックし、[ツール]、[インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
Windows 8 または Windows 8.1 を使用している場合:
- Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
- [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
Windows Server 2008 または Windows Server 2008 R2 を使用している場合:
- タスク バーで、[スタート] ボタンをクリックし、[管理ツール]、[インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
Windows Vista または Windows 7 を使用している場合:
- タスク バーで、[スタート]、[コントロール パネル] の順にクリックします。
- [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
[接続] ウィンドウで、サーバー名を展開してから、ログを構成するサイトに移動します。
[ホーム] ウィンドウで、[FTP ログ] をダブルクリックします。
- [ログ ファイル] セクションで、[W3C フィールドの選択...] をクリックします。
[ディレクトリ] で、ログ ファイルを格納するパスを指定します。 既定値は %SystemDrive%\inetpub\logs\LogFiles です。
[ログ ファイル ロールオーバー] セクションで、次のオプションを指定します。
スケジュール: 次のいずれかの値に基づいて、新しいログ ファイルを作成します。
- [毎時]: 新しいログ ファイルが 1 時間ごとに作成されます。
- [毎日]: 新しいログ ファイルが毎日作成されます。
- [毎週]: 新しいログ ファイルが毎週作成されます。
- [毎月]: 新しいログ ファイルが毎月作成されます。
ファイルの最大サイズ (バイト): ファイルが特定のサイズ (バイト) に達したときに、新しいログ ファイルを作成します。 最小ファイル サイズは、1048576 バイトです。 この属性を 1048576 バイト未満の値に設定すると、既定値は暗黙的に 1048576 バイトと見なされます。
新しいログ ファイルを作成しない: ログ ファイルは 1 つで、情報が記録されるにつれて増大します。
ログ ファイルの命名とログ ファイル ロールオーバーの時刻に、ローカル サーバーの時刻を使用することを指定するには、[ファイル名およびロールオーバーに地域設定を使用する] を選択します。 これが選択されていない場合は、世界協定時 (UTC) が使用されます。
[操作] ペインで [適用] をクリックします。
構成
属性
属性 | 説明 | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
directory |
省略可能な文字列属性。 ログ ファイルとログ関連のサポート ファイルが格納されるログ ディレクトリを指定します。 既定値は %SystemDrive%\inetpub\logs\LogFiles です。 |
||||||||||||||||||||||||||||||||||||||||||||
enabled |
省略可能な Boolean 属性です。 ログを有効にするには true、それ以外の場合は false。 既定値は true です。 |
||||||||||||||||||||||||||||||||||||||||||||
localTimeRollover |
省略可能な Boolean 属性です。 新しいログ ファイルをローカル時刻に基づいて作成するには true、それ以外の、協定世界時 (UTC) (旧称グリニッジ標準時 (GMT)) の場合は false。 注: 設定に関係なく、W3C 拡張ログの各ログ レコードのタイム スタンプは UTC ベースです。 既定値は false です。 |
||||||||||||||||||||||||||||||||||||||||||||
logExtFileFlags |
省略可能なフラグ属性。 サイトのイベントをログ中に、ログ ファイル (W3C 拡張ログ ファイル形式を使うとき) と ODBC データ ソースのいずれかに書き込まれる情報のカテゴリを指定します。 logExtFileFlags 属性には、次の値のうち 1 つ以上を指定できます。 複数の値を指定する場合はコンマ (,) で区切ります。 既定値は、 Date 、Time 、ClientIP 、UserName 、ServerIP 、Method 、UriStem 、FtpStatus 、Win32Status 、FtpSubStatus 、ServerPort 、Session 、および FullPath です。
|
||||||||||||||||||||||||||||||||||||||||||||
period |
省略可能な列挙型属性。 FTP サービスが新しいログ ファイルを作成する頻度を指定します。 period 属性には、次のいずれかの値を指定できます。既定値は Daily です。
|
||||||||||||||||||||||||||||||||||||||||||||
selectiveLogging |
省略可能なフラグ属性。 FTP ログの詳細度を指定します。 既定値は LogSuccessful,LogError,LogInfrastructure です。
|
||||||||||||||||||||||||||||||||||||||||||||
truncateSize |
省略可能な int64 属性。 到達したら新しいログ ファイルを作成する、ログ ファイルの最大サイズ (バイト) を指定します。 この値は、 period 属性に MaxSize が選ばれているときにのみ適用されます。 最小ファイル サイズは 1,048,576 バイトです。 この属性を 1,048,576 バイト未満の値に設定すると、既定値は暗黙的に 1,048,576 バイトとみなされます。既定値は 20971520 です。 |
子要素
なし。
構成サンプル
次の構成例は、インフラストラクチャ コマンドをログに記録せず、ログ ファイルを毎日ローテーションし、追加のデバッグ オプションが既定のフィールドに追加されていることを指定するカスタム ログ オプションを含む FTP を示しています。
<site name="ftp.example.com" id="5">
<application path="/">
<virtualDirectory path="/" physicalPath="c:\inetpub\www.example.com" />
</application>
<bindings>
<binding protocol="ftp" bindingInformation="*:21:" />
</bindings>
<ftpServer serverAutoStart="true">
<security>
<authentication>
<basicAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
</authentication>
</security>
<logFile period="Daily"
logExtFileFlags="Date, Time, ClientIP, UserName, ServerIP, Method, UriStem, FtpStatus, Win32Status, ServerPort, FtpSubStatus, Session, FullPath, Info"
selectiveLogging="LogSuccessful, LogError" />
</ftpServer>
</site>
サンプル コード
次の例は、FTP サイトのログ記録の有効化、特定のパスに対する FTP サイト用のログ ファイル ディレクトリの構成、およびログ ファイルの毎日のリサイクルの指定を示しています。
AppCmd.exe
appcmd.exe set config -section:system.applicationHost/sites /[name='ftp.example.com'].ftpServer.logFile.directory:"C:\logs\LogFiles" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites /[name='ftp.example.com'].ftpServer.logFile.period:"Daily" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites /[name='ftp.example.com'].ftpServer.logFile.enabled:"True" /commit:apphost
Note
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");
ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"ftp.example.com");
if (siteElement == null) throw new InvalidOperationException("Element not found!");
ConfigurationElement ftpServerElement = siteElement.GetChildElement("ftpServer");
ConfigurationElement logFileElement = ftpServerElement.GetChildElement("logFile");
logFileElement["directory"] = @"C:\logs\LogFiles";
logFileElement["period"] = @"Daily";
logFileElement["enabled"] = true;
serverManager.CommitChanges();
}
}
private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
{
foreach (ConfigurationElement element in collection)
{
if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
{
bool matches = true;
for (int i = 0; i < keyValues.Length; i += 2)
{
object o = element.GetAttributeValue(keyValues[i]);
string value = null;
if (o != null)
{
value = o.ToString();
}
if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
{
matches = false;
break;
}
}
if (matches)
{
return element;
}
}
}
return null;
}
}
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 sitesCollection As ConfigurationElementCollection = sitesSection.GetCollection
Dim siteElement As ConfigurationElement = FindElement(sitesCollection, "site", "name", "ftp.example.com")
If (siteElement Is Nothing) Then
Throw New InvalidOperationException("Element not found!")
End If
Dim ftpServerElement As ConfigurationElement = siteElement.GetChildElement("ftpServer")
Dim logFileElement As ConfigurationElement = ftpServerElement.GetChildElement("logFile")
logFileElement("directory") = "C:\logs\LogFiles"
logFileElement("period") = "Daily"
logFileElement("enabled") = True
serverManager.CommitChanges()
End Sub
Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray keyValues() As String) As ConfigurationElement
For Each element As ConfigurationElement In collection
If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then
Dim matches As Boolean = True
Dim i As Integer
For i = 0 To keyValues.Length - 1 Step 2
Dim o As Object = element.GetAttributeValue(keyValues(i))
Dim value As String = Nothing
If (Not (o) Is Nothing) Then
value = o.ToString
End If
If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then
matches = False
Exit For
End If
Next
If matches Then
Return element
End If
End If
Next
Return Nothing
End Function
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 sitesCollection = sitesSection.Collection;
var siteElementPos = FindElement(sitesCollection, "site", ["name", "ftp.example.com"]);
if (siteElementPos == -1) throw "Element not found!";
var siteElement = sitesCollection.Item(siteElementPos);
var ftpServerElement = siteElement.ChildElements.Item("ftpServer");
var logFileElement = ftpServerElement.ChildElements.Item("logFile");
logFileElement.Properties.Item("directory").Value = "C:\\logs\\LogFiles";
logFileElement.Properties.Item("period").Value = "Daily";
logFileElement.Properties.Item("enabled").Value = true;
adminManager.CommitChanges();
function FindElement(collection, elementTagName, valuesToMatch) {
for (var i = 0; i < collection.Count; i++) {
var element = collection.Item(i);
if (element.Name == elementTagName) {
var matches = true;
for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
var property = element.GetPropertyByName(valuesToMatch[iVal]);
var value = property.Value;
if (value != null) {
value = value.toString();
}
if (value != valuesToMatch[iVal + 1]) {
matches = false;
break;
}
}
if (matches) {
return i;
}
}
}
return -1;
}
VBScript
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")
Set sitesCollection = sitesSection.Collection
siteElementPos = FindElement(sitesCollection, "site", Array("name", "ftp.example.com"))
If siteElementPos = -1 Then
Wscript.Echo "Element not found!"
WScript.Quit
End If
Set siteElement = sitesCollection.Item(siteElementPos)
Set ftpServerElement = siteElement.ChildElements.Item("ftpServer")
Set logFileElement = ftpServerElement.ChildElements.Item("logFile")
logFileElement.Properties.Item("directory").Value = "C:\logs\LogFiles"
logFileElement.Properties.Item("period").Value = "Daily"
logFileElement.Properties.Item("enabled").Value = true
adminManager.CommitChanges()
Function FindElement(collection, elementTagName, valuesToMatch)
For i = 0 To CInt(collection.Count) - 1
Set element = collection.Item(i)
If element.Name = elementTagName Then
matches = True
For iVal = 0 To UBound(valuesToMatch) Step 2
Set property = element.GetPropertyByName(valuesToMatch(iVal))
value = property.Value
If Not IsNull(value) Then
value = CStr(value)
End If
If Not value = CStr(valuesToMatch(iVal + 1)) Then
matches = False
Exit For
End If
Next
If matches Then
Exit For
End If
End If
Next
If matches Then
FindElement = i
Else
FindElement = -1
End If
End Function