PutData Method  
 

Upload the contents of a string or byte array and store it in a file on the server.

Syntax

object.PutData( RemoteFile, Buffer, [Length], [Reserved] )

Parameters

RemoteFile
A string that specifies the file on the server that will contain the data being transferred. If the file already exists, it will be overwritten. The file pathing and name conventions must be that of the server.
Buffer
This parameter specifies the local buffer that the data will be copied from. If the parameter is a String type, then the data will be written as a string of characters. For binary data, it is recommended that this parameter specify a Byte array.
Length
An optional integer argument that specifies the amount of data to be copied from the buffer. If this argument is omitted, the entire contents of the buffer is transferred to the server. For strings, this value specifies the number of characters to be copied. For byte arrays, this value specifies the number of bytes.
Reserved
An argument reserved for future expansion. This argument should always be omitted or specified as a numeric value of zero.

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

The PutData method transfers data from a local buffer and stores it on a file on the server. 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 using a String buffer, the contents of the buffer will automatically be converted to UTF-8 encoded text. Most applications support UTF-8 encoding, however if you need to store the text using a different encoding you can change the value of the CodePage property and use the PutText method instead.

Never use a String variable to upload binary data. This method will automatically attempt to convert the contents of the string to UTF-8 encoded text and this can corrupt the data. If you need to upload binary data using the PutData method, you should always use a Byte array.

The value specified with the Length parameter may not be identical to the size of the text file created 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 upload text which includes non-ASCII characters, those characters will be UTF-8 encoded. If you want to upload an exact copy of the data in your buffer, make sure the FileType property is set to ftpFileTypeBinary and use a Byte array instead of a String variable.

See Also

CodePage Property, FileType Property, GetData Method, GetFile Method, GetText Method, PutFile Method, PutText Method, OnProgress Event