GetFileSize Method  
 

Returns the size of the specified file on the server.

Syntax

object.GetFileSize( RemoteFile, FileSize )

Parameters

RemoteFile
A string that specifies the name of the file on the server. The filename cannot contain any wildcard characters and must follow the naming conventions of the operating system the server is hosted on.
FileSize
A numeric variable which will be set to the size of the file on the server. Note that if the variable is not large enough to contain the file size, an overflow error will occur. This parameter must be passed by reference.

Return Value

A value of zero is returned if the operation was successful, otherwise a non-zero error code is returned which indicates the cause of the failure.

Remarks

This method uses the SIZE command to determine the length of the specified file. Not all servers implement this command, in which case the method will fail. You can use the Features property to determine what features are available and/or enabled on the server.

Note that if the file on the server is a text file, it is possible that the value returned by this method will not match the size of the file when it is downloaded to the local system. This is because different operating systems use different sequences of characters to mark the end of a line of text, and when a file is transferred in text mode, the end of line character sequence is automatically converted to a carriage return-linefeed, which is the convention used by the Windows platform.

Some FTP servers will refuse to return the size of a file if the current file type is set to ftpFileTypeText because the size of a text file on the server may not accurately reflect what the size of the file will be on the local system.

Example

The following example demonstrates how to retrieve the size a file on the server:

Dim nFileSize As Long

nError = FtpClient1.GetFileSize(strFileName, nFileSize)
If nError > 0 Then
    MsgBox FtpClient1.LastErrorString, vbExclamation
    Exit Sub
End If

MsgBox "The size of " & strFileName & " is " & nFileSize " bytes"

See Also

Features Property, GetFileStatus Method, GetFileTime Method