CFtpClient::GetFileZoneInfo Method  
 
BOOL GetFileZoneInfo(
  LPCTSTR lpszLocalFile,  
  LPDWORD lpdwZoneId,  
  LPTSTR lpszHostUrl,  
  INT nMaxLength  
);
BOOL GetFileZoneInfo(
  LPCTSTR lpszLocalFile,  
  LPDWORD lpdwZoneId,  
  CString& strHostUrl  
);

The GetFileZoneInfo method returns the security zone information for a local file.

Parameters

lpszLocalFile
A null-terminated string that specifies the name of a local file. This parameter must specify a regular file which exists on the local system and the current process must have permission to access and read from the file. If the file path includes environment variables surrounded in percent (%) symbols, the variables will be expanded. This parameter cannot be NULL.
lpdwZoneId
A pointer to an unsigned integer which will contain the zone ID assigned to the file when the method returns. It may be one of the following values:
Value Description
SECURITY_ZONE_NONE The file does not have a zone identifier associated with it.
SECURITY_ZONE_LOCAL The file is considered to be part of the local computer zone.
SECURITY_ZONE_INTRANET The file originates from the local intranet zone, such as an internal corporate network.
SECURITY_ZONE_TRUSTED The file originates from a site in the Trusted Sites zone.
SECURITY_ZONE_INTERNET The file was downloaded from the Internet and is treated with caution by Windows.
SECURITY_ZONE_RESTRICTED The file originates from a site in the Restricted Sites zone, which is used for untrusted content.
lpszHostUrl
An optional pointer to a string buffer which will contain the URL used to originally download the file. This information is not always available, in which case an empty string will be returned. If this information is not required, this parameter may be NULL and the nMaxLength parameter should be specified with a value of zero. An alternate version of this method accepts a reference to a CString object which will contain the URL when the method returns.
nMaxLength
An integer value which specifies the maximum number of characters which can be copied into the lpszHostUrl string including the terminating null character. If the lpszHostUrl parameter is NULL, this value should be zero. If the buffer is not large enough to contain the entire URL, the string will be truncated. The maximum allowed URL length is 2,048 characters.

Return Value

If the method succeeds, the return value is non-zero. If the method fails or zone information is not available, the method returns zero. To get extended error information, call the GetLastError method.

Remarks

When a file is downloaded from the Internet or other external sources, Windows may assign a zone identifier to the file using an alternate data stream named Zone.Identifier. This metadata helps determine how the system treats the file with respect to security, such as whether to prompt the user with a warning before opening it.

The GetFileZoneInfo method retrieves the zone ID associated with the specified local file, allowing an application to determine the origin and trust level of that file. This can be useful when implementing additional security measures, auditing downloaded content, or providing user warnings about potentially untrusted files.

The file name specified by the lpszLocalFile parameter must not reference a network location. This includes UNC paths (such as \\server\share\file.txt) and drive letters that are mapped to network shares. Security zone metadata cannot be read from files on network volumes because the SMB protocol does not support alternate data streams.

In addition to the zone ID, this method can optionally return the source URL used to download the file. This information, if present, is extracted from the same alternate data stream. Not all files will include this URL, as it depends on the program or browser that downloaded the file and whether it preserved this metadata. This method will not return an error if the URL stored with the security zone information is not a valid FTP URL. For example, it's possible for this method to return zone information with an HTTP URL. You can use the ValidateUrl method to determine if the host URL is a valid FTP URL.

Note that not all file systems support alternate data streams. For example, FAT32 volumes do not support them, and in such cases, zone information will not be available. Additionally, some applications may remove this metadata after download or strip it during file copy operations. The absence of zone information does not guarantee that a file is safe or originated locally.

If you wish to distinguish between a file which exists without any zone information, and an error condition where the file does not exist or could not be accessed, check the last error code. If this method returns zero and the GetLastError method returns NO_ERROR, this indicates the file name is valid and it exists, but the Zone.Identifier alternate data stream does not exist.

For more detailed information about the security zone identifiers, refer to the SetDefaultZoneId method. To change or remove the security zone metadata from a local file, use the SetFileZoneInfo method.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csftpv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also