LOGGING_PARAMETERS 结构

定义 FTP 活动的信息,例如客户端和服务器的用户名、会话 ID、IP 地址。 开发人员可以选择在实现 IFtpLogProvider 接口时要使用的日志记录信息。

语法

struct LOGGING_PARAMETERS 
{ 
   LPWSTR pszSessionId; 
   LPWSTR pszSiteName; 
   LPWSTR pszUserName; 
   LPWSTR pszHostName; 
   LPWSTR pszRemoteIpAddress; 
   unsigned long dwRemoteIpPort; 
   LPWSTR pszLocalIpAddress; 
   unsigned long dwLocalIpPort; 
   unsigned __int64 BytesSent; 
   unsigned __int64 BytesReceived; 
   LPWSTR pszCommand; 
   LPWSTR pszCommandParameters; 
   LPWSTR pszFullPath; 
   unsigned long dwElapsedMilliseconds; 
   unsigned long FtpStatus; 
   unsigned long FtpSubStatus; 
   HRESULT hrStatus; 
   LPWSTR pszInformation; 
}; 

成员

成员名称 定义
BytesReceived 从客户端接收的字节数。
BytesSent 发送到客户端的字节数。
pszCommand FTP 命令。
pszCommandParameters 与 FTP 命令相关的参数。
dwElapsedMilliseconds 操作完成所花费的毫秒数。
FtpStatus 当前命令的 FTP 状态。
FtpSubStatus 当前命令的 FTP 子状态。
pszFullPath FTP 命令的操作的完整路径。
pszHostName FTP 虚拟主机名。
hrStatus 操作的 Windows 错误代码。
pszInformation 命令的其他故障排除信息。
pszLocalIpAddress 客户端连接到的本地 IP 地址。
dwLocalIpPort 服务器的 TCP/IP 端口。
pszRemoteIpAddress 客户端的 IP 地址。
dwRemoteIpPort 客户端的 TCP/IP 端口。
pszSessionId 会话 ID。
pszSiteName 正在记录的服务器实例的名称。
pszUserName 用户的名称。

示例

下面的代码示例演示如何使用 IFtpLogProvider 接口为 FTP 服务创建自定义日志记录模块。

public: 
   STDMETHOD(Log)(LOGGING_PARAMETERS * pLoggingParameters) 
   { 
      // Note: You would add your own custom logic here. 
      HRESULT hr = S_OK; 
      DWORD dwResult; 
      HANDLE hFile; 
      char szLogEntry[256]=""; 
      const DWORD FILE_WRITE_TO_END_OF_FILE = 0xffffffff; 
 
      OVERLAPPED Overlapped = { 0 }; 
      Overlapped.Offset = FILE_WRITE_TO_END_OF_FILE; 
      Overlapped.OffsetHigh = -1; 
 
      // Retrieve the current date and time for the log entry. 
      SYSTEMTIME CurrentTime; 
      GetSystemTime(&CurrentTime); 
 
      // Open the log file for output. 
      hFile = CreateFile( 
         L"\\\\?\\C:\\logfiles\\myftpsite\\myftplog.log", 
         GENERIC_WRITE, 
         FILE_SHARE_READ, 
         NULL, 
         OPEN_ALWAYS, 
         FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, 
         NULL); 
 
      // Return an error if a failure occurs. 
      if (hFile == INVALID_HANDLE_VALUE) 
      { 
         hr = HRESULT_FROM_WIN32(GetLastError()); 
         goto EXIT; 
      } 
 
      // Format the log entry. 
      hr = StringCchPrintfA( 
         szLogEntry,256, 
         "%04d-%02d-%02d\t%02d:%02d:%02d\t%S\t%d\r\n", 
         CurrentTime.wYear,CurrentTime.wMonth,CurrentTime.wDay, 
         CurrentTime.wHour,CurrentTime.wMinute,CurrentTime.wSecond, 
         pLoggingParameters->pszCommand, 
         pLoggingParameters->FtpStatus); 
 
      // Test for error. 
      if (FAILED(hr)) 
      { 
         // Return the error if a failure occurs. 
         hr = HRESULT_FROM_WIN32(GetLastError()); 
         goto EXIT; 
      } 
 
      // Write the log entry to the log file. 
      if(!WriteFile(hFile, szLogEntry, 
         strlen(szLogEntry), &dwResult, &Overlapped)) 
      { 
         // Return an error if a failure occurs. 
         hr = HRESULT_FROM_WIN32(GetLastError()); 
         goto EXIT; 
      } 
 
EXIT: 
      // Close the log file if it is open. 
      if(CloseHandle(hFile)==0) 
      { 
         // Return an error if a failure occurs. 
         hr = HRESULT_FROM_WIN32(GetLastError()); 
      } 
      return hr; 
   } 

要求

类型 说明
客户端 - Windows 7 上的 IIS 7.5
- Windows 8 上的 IIS 8.0
- Windows 10 上的 IIS 10.0
服务器 - Windows Server 2008 R2 上的 IIS 7.5
- Windows Server 2012 上的 IIS 8.0
- Windows Server 2012 R2 上的 IIS 8.5
- Windows Server 2016 上的 IIS 10.0
产品 - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0
参考 ftpext.tlb

另请参阅

IFtpLogProvider 接口