|
INT GetData( |
|
LPCTSTR lpszRemoteFile, |
|
|
LPBYTE lpBuffer, |
|
|
LPDWORD lpdwLength |
|
); |
INT GetData( |
|
LPCTSTR lpszRemoteFile, |
|
|
HGLOBAL* lpBuffer, |
|
|
LPDWORD lpdwLength |
|
); |
INT GetData( |
|
LPCTSTR lpszRemoteFile, |
|
|
LPTSTR lpBuffer, |
|
|
DWORD dwMaxLength |
|
); |
INT GetData( |
|
LPCTSTR lpszRemoteFile, |
|
|
CString& strBuffer |
|
); |
The GetData method transfers the contents of a file on the
server to the specified buffer.
Parameters
- lpszRemoteFile
- A pointer to a string that specifies the file
on the server that will be transferred to the local system.
The file naming conventions must be that of the host operating system.
- lpBuffer
- A pointer to a buffer which will contain the data transferred
from the server. In alternate forms of the method, this
argument may also be a pointer to a global memory handle or
reference a CString object.
- lpdwLength
- A pointer to an unsigned integer which should be
initialized to the maximum number of bytes that can be copied to
the buffer specified by the lpBuffer parameter. If the
lpBuffer parameter points to a global memory handle, the
length value should be initialized to zero. When the method
returns, this value will be updated with the actual length of the
file that was downloaded.
- dwMaxLength
- An unsigned integer value which specifies the maximum
number of characters can be copied into the lpBuffer string.
This parameter is used with the version of the method that returns
the data in a character array and includes the terminating null
character. This value must be greater than one and the
lpBuffer parameter cannot be NULL, otherwise the method will
return an error.
Return Value
If the method succeeds, the return value is the server result
code. If the method fails, the return value is FTP_ERROR. To get
extended error information, call GetLastError.
Remarks
The GetData method is used to download the contents of a
remote file into a local buffer. The method may be used in one of two
ways, depending on the needs of the application. The first method is
to pre-allocate a buffer large enough to store the contents of the
file. In this case, the lpBuffer parameter will point to the
buffer that was allocated, the value that the lpdwLength
parameter points to should be initialized to the size of that
buffer.
The second method that can be used is have the lpBuffer
parameter point to a global memory handle which will contain the file
data when the method returns. In this case, the value that the
lpdwLength parameter points to must be initialized to zero. It
is important to note that the memory handle returned by the method
must be freed by the application, otherwise a memory leak will occur.
See the example code below.
If the third method or fourth method is used, where the data is
returned in a string buffer, the data may be modified
so that the end-of-line character sequence matches the convention
used by the Windows platform (a carriage return character followed by
a linefeed). If Unicode is being used, the data will be converted
from a byte array to a Unicode string. An application should only use
these versions of the GetData method if the remote file
contains text.
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 FTP_EVENT_PROGRESS event will be
periodically fired, enabling the application to update any user
interface controls. Event notification must be enabled, either by
calling EnableEvents, or by registering a callback function
using the RegisterEvent method.
To determine the current status of a file transfer while it is in
progress, use the GetTransferStatus method.
Example
HGLOBAL hgblBuffer = (HGLOBAL)NULL;
LPBYTE lpBuffer = (LPBYTE)NULL;
DWORD cbBuffer = 0;
// Return the file data into block of global memory allocated by
// the GlobalAlloc function; the handle to this memory will be
// returned in the hgblBuffer parameter
nResult = pClient->GetData(lpszRemoteFile, &hgblBuffer, &cbBuffer);
if (nResult != FTP_ERROR)
{
// Lock the global memory handle, returning a pointer to the
// contents of the file data
lpBuffer = (LPBYTE)GlobalLock(hgblBuffer);
// After the data has been used, the handle must be unlocked
// and freed, otherwise a memory leak will occur
GlobalUnlock(hgblBuffer);
GlobalFree(hgblBuffer);
}
Requirements
Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header File: cstools10.h
Import Library: csftpv10.lib
Unicode: Implemented as Unicode and ANSI versions.
See Also
ChangeDirectory,
EnableEvents,
GetFile,
GetTransferStatus,
PutData, PutFile,
RegisterEvent,
SetBufferSize
|
|