FVSDK_ERROR_CODE FVSDK_WriteFile(FVSDK_Session* pSession, PBYTE pBuffer, int* pnBufferSize, BOOL bEnd);
Writes data to a file created with FVSDK_CreateFile() or FVSDK_OpenFileRW().
pSession
A pointer to the FVSDK_Session that is to perform the operation.
pBuffer
A pointer to data to be written to the remote file.
pnBufferSize
A pointer to the amount of data contained within pBuffer to be written to the remote file. On return, contains the number of bytes written to the file if > 0. If < 0 this value represents an internal error number.
bEnd
Set to TRUE if this is the last buffer to be written for the file. This is an especially important parameter when compression is in use since uploading files using compression requires extra internal buffers for the compression functions.
FVSDK_YES if the function was successful; FVSDK_NO if data could not be written to the remote file. Error codes can be found in FVSDK_ErrorCodes.h.
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_CreateFile(pSession, sRemoteName, 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) {
CFileStatus Status;
// get the status of the local file, then set the date and time of the remote file
if (File.GetStatus(Status)) {
tm tmLocalTime;
// get the last time the file was modified
Status.m_mtime.GetLocalTm(&tmLocalTime);
// set the date and time of the remote file, put up an error if it fails
if (FVSDK_SetFileDateAndTime(pSession, sRemoteName, &tmLocalTime) != FVSDK_YES)
AfxMessageBox("Unable to set the remote file's date and time.", MB_ICONEXCLAMATION);
} // if
} // if
else
AfxMessageBox("Unable to close the remote file", MB_ICONEXCLAMATION);
} // if
else
AfxMessageBox("Unable to create the remote file", MB_ICONEXCLAMATION);
// ... upload cleanup ...