SocketTools .NET Edition

FileTransfer.GetFileType Method (String, FileTransferType, Boolean)

Determine the file transfer type based on the file extension or contents.

[Visual Basic]
Overloads Public Function GetFileType( _
   ByVal fileName As String, _
   ByRef fileType As FileTransferType, _
   ByVal scanFile As Boolean _
) As Boolean
[C#]
public bool GetFileType(
   string fileName,
   ref FileTransferType fileType,
   bool scanFile
);

Parameters

fileName
A string value which specifies the local path to a file.
fileType
A FileTransferType enumeration passed by reference which specifies the type of file associated with the file extension.
scanFile
A boolean value which specifies if the contents of the file should be checked to determine the possible file type. If this 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.

Return Value

This method returns a boolean value. If the method succeeds, the return value is true. If the method fails, the return value is false. To get extended error information, check the value of the LastError property.

Remarks

This method is used to determine the file transfer type to be used when uploading or downloading files. This method is used internally to determine the transfer mode when the FileType property is set to FileTransferType.fileAuto.

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 FtpFileType.fileImage, 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 bScanFile parameter is true and the file does not exist, 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 FtpFileType.fileImage because they can contain embedded null characters.

See Also