Download the contents of a file on the server and return it in a
string or byte array.
object.GetData( RemoteFile, Buffer,
[Length], [Reserved] )
- A string that specifies the file on the server that will
be transferred to the local system. The file pathing and name
conventions must be that of the server.
- This parameter specifies the local buffer that the data will be
stored in. If the variable is a String type, then the data will be
returned as a string of characters. This is the most appropriate
data type to use if the file on the server is a text file. If the remote
file contains binary data, it is recommended that a Byte array
variable be specified as the argument to this method.
- An optional integer argument passed by reference which will
specify the amount of data received from the server when the method returns.
For strings, this value specifies the number of characters that were
returned by the server. For byte arrays, this value specifies the
number of bytes that were returned.
- An argument reserved for future expansion. This argument should
always be omitted or specified as a numeric value of zero.
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.
The GetData method transfers data from a file on the server
to the local system, storing it in the specified buffer . This method
will cause the current thread to block until the file transfer
completes, a timeout occurs or the transfer is canceled. During the
transfer, the OnProgress event will fire periodically,
enabling the application to update any user interface objects such as
a progress bar.
If you are returning the data into a String variable and the text you
receive appears to corrupted or characters are being replaced with question
marks or other symbols, it is likely the file on the server is using a
different character encoding. Most applications use UTF-8 encoding to
represent non-ASCII characters; however, some text files may use a localized
character set rather than using Unicode. Using the GetText and
PutText methods in combination with this property will change how
that text is converted to Unicode.
The value returned in the Length parameter may not be
identical to the size of a text file on the server. The end-of-line
conventions may differ between the server and the local system, and
conversion to Unicode may cause differences in the character count.
For example, if this method is used to download a UTF-8 encoded text
file which includes non-ASCII characters, those characters will be
converted to 16-bit Unicode characters. If you want an exact copy of
the file as it is on the server, make sure the FileType
property is set to ftpFileTypeBinary and store the data in a
Byte array instead of a String variable.