ThingWorx Edge C SDK > Running the C SDK > Initializing the File Manager (Optional)
Initializing the File Manager (Optional)
If using the directory browsing and file transfer capability of the SDK, perform the following steps:
1. Set the staging directory — You must set the staging directory before initializing the FileManager. The default directory of the FileManager is most likely owned by root and will require a change to either the location of the staging directory and the ownership of the staging directory, or running the application as a user with the correct permissions. For example:
/* Staging Directory Variable */
/* must be set before initializing file manager*/

2. Initialize the FileManager singleton. For example:
/* Initialize the FileTransfer Manager */

3. Define any virtual directories — Virtual directories allow you to expose only a subset of the entire file system of the device to the server for browsing and file transfer. This restriction is for both performance and security reasons. For example:
/* Create our virtual directories */
twFileManager_AddVirtualDir(thingName, "tw", "/opt/thingworx");
twFileManager_AddVirtualDir(thingName, "tw2", "/twFile_tmp");

Registering a virtual directory with the FileManager consists of mapping a unique name to an absolute path of a directory in your file system. Note that all subdirectories of the specified directory in the file system will be exposed to the server. Multiple virtual directories can be defined and there is no requirement that they be contiguous.
4. Register the FileCallback function that was previously defined so that the FileManager will call that function when any file transfer events occur. You can provide a wildcard filter so that only file transfer events of files that match the filter call the callback function. In addition, callbacks can be set up as “one-shots” such that the callback is unregistered automatically after it is invoked the first time
. For example:
/* Register the file transfer callback function */
twFileManager_RegisterFileCallback(fileCallbackFunc, NULL, FALSE, NULL);
5. OPTIONAL: By default, WebSocket compression will be used for all WebSocket communications, including file transfers. If you need to disable compression, call the tw_Api_DisableWebSocketCompression() function. Note that this function does not return anything.
In general, compression can be disabled after the API is initialized by calling the function:
twApi_DisableWebSocketCompression ();
When you disable compression, compression will not be used for any WebSocket communications, including file transfers.
The C SDK v.2.1.2 provides improved logging for staging directory failures. If a file transfer fails to complete when the staging directory is on a separate partition (RAMDisk) from the final destination, use a DEBUG build of our application to see the logging around this failure (in twListEntities()).