Posted By: David Faust
Applications occasionally have a need to move entire files between the client and server. These files may be c‑tree files or not. Consider reports that are run server side or centralized configuration files.
When using the c‑treeACE Replication Agent applications usually expect the replication activity to commence from a consistent state between two servers. There are multiple ways to copy a data file, including the c‑treeACE Dynamic Dump, or system level utilities. Some developers have even custom coded file copy routines into the CTUSER() feature using the c‑treeACE Server SDK.
c‑treeACE V10 introduced an alternative utility function to easily move files where needed.
The c‑treeACE API function ctTransferFile() can be used to transfer a file between a c‑treeACE client and the c‑treeACE database server.
The ctTransferFile() function handles either sending or receiving a file as well as a configurable communication block size for efficient transfer. A simple structure (ctXFRFL) is defined with all of the parameters required and then passed to the function. An overwrite mode is necessary to prevent overwriting existing destination files.
For security reasons, this feature is disabled, by default, and requires the calling user to be a member of the ADMIN group. To enable this feature, specify the following in the c‑treeACE configuration file:
To allow a non-ADMIN user to call ctTransferFile() specify the following configuration keyword:
NINT rc = 0;
memset(srcnam, 0, 80);
memset(dstnam, 0, 80);
xferfile = (pctXFRFL) malloc (sizeof(ctXFRFL));
Handle_Error("Bad malloc on xferfile", 0);
xferfile->ver = ctXFRFL_CUR;
xferfile->mode = ctXFRFIL_RECV | ctXFRFIL_OVRWRT;
xferfile->srcnam = srcnam;
xferfile->dstnam = dstnam;
xferfile->blksiz = 32768;
xferfile->ackint = 0;
rc = ctTransferFile(xferfile);
Handle_Error("File transfer failed.", rc);