<< Back


FVSDK_OpenFileRW

Synopsis

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

Description

Opens a file on the server for upload (bRead = FALSE) or download (bRead = TRUE). After a file is successfully opened, the file may be read from or written to using FVSDK_ReadFile() or FVSDK_WriteFile(). The file cannot be written to and read from at the same time.

For ease of use, use FVSDK_OpenFile() to open a file for download. Use FVSDK_CreateFile() to create a file to be uploaded.

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 or create 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 or created in the current directory.

bRead

Set to TRUE to download a file (same as using FVSDK_OpenFile()), set to FALSE to upload a file (same as using FVSDK_CreateFile()).

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 severs support the resume capability (the REST command).

Return Value

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

Example

CStdioFile      File;
FVSDK_Session*  pSession;
CString         sRemoteName;

// ... upload preparation ...

// get the local file size
FVSDK_FILE_SIZE fsLocalFileSize = File.GetLength();

// create the file to be uploaded on the server
if (FVSDK_OpenFileRW(pSession, sRemoteName, FALSE, TRUE, 0) == FVSDK_YES) {
    BYTE            Buffer[1024];
    int             nBytes;
    FVSDK_FILE_SIZE fsWritten = 0;

    // read all of the data from the local file, and write it to the remote file
    while ((nBytes = File.Read(Buffer, sizeof(Buffer))) > 0) {

        // do the write
        if (FVSDK_WriteFile(pSession, Buffer, &nBytes, ((nBytes + fsWritten) >= fsLocalFileSize)) != FVSDK_YES) {

            // put up an error message
            AfxMessageBox("Unable to write to the remote file", MB_ICONEXCLAMATION);

            // get out
            break;
        } // if

        // increment the number of bytes written to the file
        fsWritten += nBytes;
    } // while

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

// ... upload cleanup ...