ThingWorx Edge .NET SDK > ThingWorx Edge .NET SDK Reference > Transferring Files with the .NET SDK
  
Transferring Files with the .NET SDK
The .NET SDK can support file transfer to and from the ThingWorx platform. File transfers are performed over the WebSocket connection maintained with the platform, so there is no need for the client application to open another connection.
To support file transfers in your client application, you must use the FileTransferVirtualThing class to enable the functionality and define the directories available for file operations. A virtual directory maps a unique name to an absolute path of a directory in the file system. All subdirectories of the specified directory are exposed to the ThingWorx platform. You can define multiple virtual directories. The directories do not need to be contiguous.
For more information, see
.NET SDK: FileTransferVirtualThing Class
Virtual Directories
Methods of the FileTransferVirtualThing Class
Additional Parameters for a File Transfer
.NET SDK: FileTransferVirtualThing Class
The .NET SDK has full support for all the remote directory/file browsing capabilities of ThingWorx platform, as well as bidirectional file transfer. To use the directory browsing and file transfer capabilities of this SDK, you must:
Sub-class the FileTransferVirtualThing class.
Define the virtual directories.
Virtual Directories
To enhance performance and security, virtual directories allow you to expose only a subset of a the entire file system of a device to the ThingWorx platform for browsing and file transfer. To register a virtual directory, you must map a unique name to an absolute path for a directory in your file system. Multiple virtual directories can be defined, and they do not need to be contiguous. Also, you may register for the FileTransferStateChanged event, which fires whenever a file transfer event occurs.
* 
All subdirectories of a directory you specify for the virtual directory are exposed to the ThingWorx platform.
Methods of the FileTransferVirtualThing Class
The following methods are available on the FileTransferVirtualThing class:
AddVirtualDirectory—Adds a virtual directory to the FileManager. A named virtual directory is associated with a specific thing and has a specific path in the underlying file system. More than one virtual directory can be assigned to a single thing. This method takes the following parameters:
dirName—Name to apply to this virtual directory.
path—The absolute path to the underlying directory in the file system.
BindVirtualDirectories—Registers all virtual directories associated with this FileTransferVirtualThing with the FileManager. Virtual directories are automatically registered with the FileManager during the FileTransferVirtualThing constructor. However, if the FileManager is shut down and restarted, each FileTransferVirtualThing will need to re-register its virtual directories; this method facilitates that re-registration.
CheckStalledTransfers—Checks for any transfers that have started and stopped without completing, and deletes them.
FileTransferStateChanged—Event that fires when a file transfer completed, successfully or not.
GetFile—Retrieves a file from the ThingWorx platform. This method takes the following parameters:
sourceRepo—The name of the entity from which to retrieve the file.
sourcePath—The path to the file.
sourceFile—Name of the file.
targetPath—The local VIRTUAL path of the resulting file (not including the file name).
targetFile—Name of the resulting file in the target directory.
timeout—Timeout, in seconds, for the transfer. A zero will use the default timeout of the system.
async—If true, return immediately and call a callback function when the transfer is complete. If false, block until the transfer is complete. Note that the file callback function will be called in either case.
InitializeFileTransferManager—Initializes the FileTransferManager. This method is called automatically during the constructor of FileTransferVirtualThing. However, you may need to invoke this method to restart the File Transfer subsystem after a shutdown. This method takes the following parameter:
configInfo—Specifies the information necessary to initialize the File Manager.
ListVirtualDirs—Returns a list of virtual directories from the FileTransferManager.
RemoveVirtualDirectory—Removes a virtual directory from the FileTransferManager. This method takes the following parameter:
dirName—Name of the virtual directory to remove.
SendFile—Sends a file to the ThingWorx platform. This method takes the following parameters:
sourcePath—The virtual path to the file to send (not including the file name).
sourceFile—The name of the file to send.
targetRepo—The target repository of the file.
targetPath—The path of the resulting file in the target repository (not including the file name).
targetFile—The name of the resulting file in the target directory.
timeout—The timeout, in seconds, for the transfer. A zero will use the default timeout of the system.
async—If true, return immediately and call a callback function when the transfer is complete. If false, block until the transfer is complete. Note that the file callback function will be called in any case.
ShutdownFileTransferManager—Shuts down the FileTransferManager.
Additional Parameters for a File Transfer
You can also set the following parameters for a file transfer:
FileTransferInfo.BlockSize—The number of bytes in each block of a file to be transferred.
FileTransferInfo.MaxFileSize—The largest number of bytes in a file to be transferred.
FileTransferInfo.MD5BlockSize—The number of bytes that an MD5 buffer can contain. The number should be a multiple of 64.
FileTransferInfo.Timeout—The number of milliseconds to wait for a stalled transfer to continue before timing out the transfer.
FileTransferInfo.StagingDir—The directory to be used for collecting the bytes (or blocks of bytes) received during a file transfer.