GetAutoFileType Method  
 
UINT GetAutoFileType(
  LPCTSTR lpszFileName,  
  BOOL bScanFile  
);

The GetAutoFileType method returns the file transfer type based on the file extension or content.

Parameters

lpszFileName
A pointer to a null-terminated string which specifies the local path to the file. This parameter cannot be NULL and cannot specify a local device name or directory.
bScanFile
An optional value which specifies if the contents of the file should be scanned. A value of zero indicates that only the file extension should be used to determine the file type, while a non-zero value specifies the contents of the file should be examined if the file type cannot be determined based on its extension. This parameter value is zero (false) by default.

Return Value

If the method succeeds, the return value is the file transfer type. If the method fails, the return value is INVALID_FILE_TYPE. To get extended error information, call GetLastError.

Remarks

This method is used to determine the file transfer type to be used when uploading or downloading files. This method is called internally when FILE_TYPE_AUTO is specified as the default file type. The return value may be one of the following:

Value Description
FILE_TYPE_ASCII The file is a text file using the ASCII character set. For those servers which mark the end of a line with characters other than a carriage return and linefeed, it will be converted to the native client format. This is the file type used for directory listings.
FILE_TYPE_EBCDIC The file is a text file using the EBCDIC character set. Local files will be converted to EBCDIC when sent to the server. Remote files will be converted to the native ASCII character set when retrieved from the server. Not all servers support this file type. It is recommended that you only specify this type if you know that it is required by the server to transfer data correctly.
FILE_TYPE_IMAGE The file is a binary file and no data conversion of any type is performed on the file. This is the default file type for most data files and executable programs. If the type of file cannot be automatically determined, it will always be considered a binary file. If this file type is specified when uploading or downloading text files, the native end-of-line character sequences will be preserved.

If the file extension or contents are not recognized, the default file transfer type for the client session will be returned. This will usually be FILE_TYPE_IMAGE, however this can be changed by calling the RegisterFileType method. The file type for the current client session can be explicitly set using the SetFileType method.

If the bScanFile parameter is non-zero, the local file will be opened in a shared reading mode and up to 4,096 bytes will be examined to determine if it contains binary data. If the file is currently locked or has been opened exclusively by another process, the file type associated with the file extension will be returned instead. Text files which contain UTF-16 text will always return a file type of FILE_TYPE_IMAGE because they can contain non-ASCII characters and/or embedded null characters.

If the bScanFile parameter is non-zero and the file type cannot be determined based on the file name extension, the file specified by lpszFileName must exist and be a regular file. If the file does not exist, an error will be returned and the last error code will be set to ST_ERROR_FILE_NOT_FOUND. If the bScanFile parameter is zero, no errors will be returned if the file does not exist, the function will only check the file name extension to determine the file type. When downloading a file, the bScanFile parameter should normally be zero because the local file may not exist yet.

Requirements

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

See Also

GetFileType, RegisterFileType, SetFileMode, SetFileStructure, SetFileType