<< Back


FVSDK_OpenFile

Synopsis

FVSDK_ERROR_CODE FVSDK_OpenFile(FVSDK_Session* pSession, LPCTSTR pszFileName, BOOL bBinary, FVSDK_FILE_SIZE fsResumeLoc);

Description

Opens a file on the server for download. After a file is successfully opened, the file may be read from using FVSDK_ReadFile(). The file cannot be written to and read from at the same time. Use FVSDK_Download() to download a file or files in a single step.

This function calls FVSDK_OpenFileRW() with the bRead parameter set to TRUE.

NOTE: Only one file can be open at a time per session.

Parameters

pSession

A pointer to the FVSDK_Session that is to perform the operation.

pszFileName

The file name or path to open for download on the server. This NULL terminated string may be either a file name or a full path. If using a file name, the file will be opened in the current directory.

bBinary

Set to TRUE to transfer the file using binary (image) mode. Set to FALSE to use ASCII mode.

fsResumeLoc

When starting at the beginning of a file, use 0. When resuming a transfer, use the byte position within the file starting at 0 to (file length - 1). NOTE: Not all servers support the resume capability (the REST command).

Return Value

FVSDK_YES if the function was successful; FVSDK_NO the file was not opened. Error codes can be found in FVSDK_ErrorCodes.h.

Example

CStdioFile      File;
FVSDK_Session*  pSession;
CString         sRemoteName;

// ... download preparation ...

// attempt to open the file to be downloaded
if (FVSDK_OpenFile(pSession, sRemoteName, TRUE, 0) == FVSDK_YES) {
    BYTE    Buffer[1024];
    int     nBytes = sizeof(Buffer);

    // read all of the data from the remote file, and write it to the local file
    while (FVSDK_ReadFile(pSession, Buffer, &nBytes) == FVSDK_YES) {

        // write the data to the local file
        File.Write(Buffer, nBytes);

        // reset the buffer size
        nBytes = sizeof(Buffer);
    } // while

    // close the remote file
    if (FVSDK_CloseFile(pSession) != FVSDK_YES)
        AfxMessageBox("Unable to close the remote file.", MB_ICONEXCLAMATION);
} // if
else
    AfxMessageBox("Unable to open the remote file.", MB_ICONEXCLAMATION);

// ... download cleanup ...