GetFileType Method  
 

Returns the file type for a file on the local system.

Syntax

object.GetFileType( FileName, ScanFile )

Parameters

FileName
A string which specifies the name of a file on the local system. The file does not need to exist if the ScanFile parameter is False. If an existing file is specified, it cannot be the name of a device or a directory, otherwise the method will fail.
ScanFile
An optional Boolean value which specifies if the contents of the file should be scanned. A value of False indicates that only the file extension should be used to determine the file type, while a value of True specifies the contents of the file should be examined if the file type cannot be determined based on its extension. If this parameter is omitted, the default value is False.

Return Value

An integer value of zero or greater which identifies the file type using the same values as the FileType property. If the method fails, it will return -1 indicating an error condition. The value of the LastError property can be used to determine the cause of the failure.

Remarks

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

Value Constant Description
1 ftpFileTypeASCII 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. The constant ftpFileTypeText is an alias for this value.
2 ftpFileTypeEBCDIC 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.
3 ftpFileTypeImage 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. The constant ftpFileTypeBinary is an alias for this value.

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 ftpFileTypeImage, however this can be changed by calling the AddFileType method. The file type for the current client session can be explicitly set using the FileType property.

If the ScanFile parameter is True, 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 ftpFileTypeImage because they can contain non-ASCII characters and/or embedded null characters.

If the ScanFile parameter is True and the file type cannot be determined based on the file name extension, the file specified by FileName 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 stErrorFileNotFound. If the ScanFile parameter is False, 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 ScanFile parameter should normally be zero because the local file may not exist yet.

See Also

FileType Property, AddFileType Method, GetFile Method, PutFile Method