共用方式為


FTP 記錄檔 < logFile>

概觀

元素 <logFile> 可用來設定 FTP 月臺的活動記錄選項。

例如,您可以啟用或停用記錄、指定要儲存在記錄檔中的資訊類別,以及變更儲存記錄檔的目錄。 您也可以使用 <logFile> 元素來控制 IIS 根據記錄檔大小或時間間隔建立新記錄檔的頻率,以及) 記錄檔可以變成的位元組大小上限 (。

注意

不同于可以針對記錄檔使用 IIS、NCSA 或 W3C 格式的網站,FTP 7 服務只會以 W3C 格式儲存記錄檔。

您可以編輯 logExtFileFlags 屬性來定義 IIS 記錄的資訊類別。 預設值為 DateTimeServerIPMethodUriStemUserNameClientIPFtpStatus 、、 FtpSubStatusServerPortWin32StatusSession 、 和 。 FullPath

相容性

版本 備註
IIS 10.0 未在 IIS 10.0 中修改專案 <logFile>
IIS 8.5 未在 IIS 8.5 中修改專案 <logFile>
IIS 8.0 未在 IIS 8.0 中修改專案 <logFile>
IIS 7.5 元素 <logFile><ftpServer> 元素隨附為 IIS 7.5 的功能。
IIS 7.0 元素 <logFile><ftpServer> 元素是在 FTP 7.0 中引進,這是 IIS 7.0 的個別下載專案。
IIS 6.0 N/A

注意

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 伺服器]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,除了FTP 服務之外,您還需要選取[FTP 擴充性]。
    醒目提示 F T P 擴充性選項的螢幕擷取畫面。 .

  5. [下一步],然後在 [ 選取功能 ] 頁面上,再次按 [ 下一步 ]。

  6. 在 [確認安裝選項] 頁面上,按一下 [安裝]

  7. 在 [結果] 頁面上,按一下 [關閉]

Windows 8 或 Windows 8.1

  1. 在 [開始] 畫面上,將指標一路移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。

  2. 主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。

  3. 展開 [Internet Information Services],然後選取 [ FTP 伺服器]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
    醒目提示 F T P 擴充性資料夾的螢幕擷取畫面。

  4. 按一下 [確定]。

  5. 按一下 [關閉] 。

Windows Server 2008 R2

  1. 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。

  2. [伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS)

  3. 在 [ Web Server (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。

  4. 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,展開[FTP 伺服器]。

  5. 選取 [FTP 服務]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
    醒目提示 F T P 服務選項的螢幕擷取畫面。

  6. 按一下 [下一步] 。

  7. 在 [確認安裝選項] 頁面上,按一下 [安裝]

  8. 在 [結果] 頁面上,按一下 [關閉]

Windows 7

  1. 在工作列上,按一下 [開始],然後按一下[主控台]。

  2. 主控台中,按一下 [程式和功能],然後按一下[開啟或關閉 Windows 功能]。

  3. 展開 [Internet Information Services],然後展開 [ FTP 伺服器]。

  4. 選取 [FTP 服務]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
    Internet Information Services 資料夾子資料夾的螢幕擷取畫面。

  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) Manager]。
    • 如果您使用 Windows 8 或 Windows 8.1:

      • 按住Windows鍵,按字母X,然後按一下[主控台]。
      • 按一下 [系統管理工具],然後按兩下 [ Internet Information Services (IIS) Manager]。
    • 如果您使用 Windows Server 2008 或 Windows Server 2008 R2:

      • 在工作列上,按一下 [ 開始],指向 [ 系統管理工具],然後按一下 [ Internet Information Services (IIS) 管理員]。
    • 如果您使用 Windows Vista 或 Windows 7:

      • 在工作列上,按一下 [開始],然後按一下[主控台]。
      • 按兩下 [系統管理工具],然後按兩下 [ Internet Information Services] (IIS) Manager
  2. 在 [ 連線] 窗格中,展開伺服器名稱,然後移至您要設定記錄的月臺。

  3. 在 [ 首頁] 窗格中,按兩下 [ FTP 記錄]。
    [首頁] 窗格的螢幕擷取畫面,其中已醒目提示 F T P 記錄選項。 - 在 [ 記錄檔變換 ] 區段中,按一下 [選取 W3C 欄位...

  4. 選取記錄檔的欄位,然後按一下 [ 確定]。
    [W 3 C 記錄欄位] 對話方塊的螢幕擷取畫面,其中顯示要選取的多個欄位。

  5. 在 [目錄] 底下,指定應儲存記錄檔之位置的路徑。 預設值為 %SystemDrive%\inetpub\logs\LogFiles。

  6. 在 [ 記錄檔變換 ] 區段中,指定下列選項:

    • 排程:建立以下列其中一個值為基礎的新記錄檔:

      • 每小時:每小時建立新的記錄檔。
      • 每天:每天建立新的記錄檔。
      • [每週]:每週建立一個新的記錄檔。
      • 每月:每月建立新的記錄檔。
    • 檔案大小上限 (位元組) :當檔案達到特定大小 (位元組) 時,建立新的記錄檔。 檔案大小下限為 1048576 個位元組。 如果此屬性已設為小於 1048576 個位元組的值,則會隱含地將預設值視為 1048576 個位元組。

    • 請勿建立新的記錄檔:有一個記錄檔會在記錄資訊時繼續成長。

    • 選取 [使用本機時間進行檔案命名和變換 ],以指定記錄檔命名和記錄檔變換的時間會使用本機伺服器時間。 若未選取此元素,則會使用國際標準時間 (UTC)。
      [記錄檔變換] 區段的螢幕擷取畫面,其中顯示 [排程] 和 [檔案大小上限] 選項。

  7. 在 [動作] 窗格中按一下 [套用]

組態

屬性

屬性 描述
directory 選擇性字串屬性。

指定記錄目錄,其中會儲存記錄檔和記錄相關的支援檔案。

預設值是 %SystemDrive%\inetpub\logs\LogFiles
enabled 選擇性的 Boolean 屬性。

如果已啟用記錄,則為true;否則為 false

預設值是 true
localTimeRollover 選擇性的 Boolean 屬性。

如果根據當地時間建立新的記錄檔,則為true;否則為false表示國際標準時間 (UTC) ,先前稱為 Greenwich Mean Time (GMT) 。

注意: 不論設定為何,每個 W3C 擴充記錄記錄記錄的時間戳記都是以 UTC 為基礎。

預設值是 false
logExtFileFlags 選擇性旗標屬性。

指定當您在網站記錄事件期間使用 W3C 擴充記錄檔格式) 或 ODBC 資料來源時,寫入記錄檔 (的資訊類別。 logExtFileFlags屬性可以是下列一或多個值。 如果您指定多個值,請使用逗號分隔 (,) 。

預設值為 DateTimeServerIPMethodUriStemUserNameClientIPFtpStatus 、、 FtpSubStatusServerPortWin32StatusSession 、 和 。 FullPath
描述
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 記錄所要求的動作。 例如, USERPASS等。

數值為 128
ServerIP 記錄產生記錄檔專案之伺服器的 IP 位址。

數值為 64
ServerPort 記錄為月臺設定的伺服器埠號碼。

數值為 32768
Session 記錄 FTP 會話的唯一識別碼。 這適用于分析記錄中的會話活動。

數值為 4194304
SiteName 記錄月臺的網際網路服務名稱和實例編號。

數值為 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 選擇性旗標屬性。

指定 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 個位元組。 如果此屬性設定為小於 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

注意

當您使用 AppCmd.exe 來設定這些設定時,請務必將 認可 參數 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