cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

How to transfer file to and from the Edge using the .NET SDK

No ratings

Prerequisite

  • Download the .NET SDK from the PTC Support Portal and set up the SteamSensor Example according the directions found in the ThingWorx Help Center
  • SDK Steam Sensor Example

In ThingWorx

  • Create a Remote thing using the RemoteThingWithFileTransfer template (SteamSensor1 in example)
  • Create a file repository and execute the CreateFolder service to create a folder in the repository folder in ThingworxStorage (MyRepository in example)

In SteamThing.cs

  • At the top of the file, import the file transfer class
    • using com.thingworx.communications.client.things.filetransfer;
  • Create a virtual thing that extends FileTransferVirtualThing
    • E.g. using steam sensor Thing
      • public class SteamThing : FileTransferVirtualThing
  • Edit SteamThing as follows

{

              public SteamThing(string name, string description, string identifier, ConnectedThingClient client, Dictionary<string, string> virtualDirectories)

            : base(name, description, client, virtualDirectories)

}

In Client.cs

  • Create a new Dictionary above the Steam Things. Select any name you wish as the virtual directory name and set the directory path. In this example, it is named EdgeDirectory and set to the root of the C Drive.

Dictionary<string, string> virtualDirectories = new Dictionary<string, string>()

            {

                {"EdgeDirectory", "C:\\"}

            };

  • Modify the SteamThing to include your newly created virtual directories in the SteamThing parameters
    • // Create two Virtual Things

SteamThing sensor1 = new SteamThing("SteamSensor1", "1st Floor Steam Sensor", "SN0001", client, virtualDirectories);

SteamThing sensor2 = new SteamThing("SteamSensor2", "2nd Floor Steam Sensor", "SN0002", client, virtualDirectories);

  • To send or receive a file from the server, it is recommended that the built in GetFile and Send File are used. Create a remote service in the SDK containing either GetFile or SendFile
      • GetFile — Get a file from the Server.
        • sourceRepo — The entityName to get the file from.
        • sourcePath — The path to the file to get.
        • sourceFile — Name of the file to get.
        • 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 systems default timeout.
        • 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.
          • E.g. GetFile("MyRepository", "/", "test.txt", "EdgeDirectory", "movedFile.txt", 10000, true);
      • SendFile — Sends a file to the Server. This method takes the following parameters:
        • sourcePath — The VIRTUAL path to the file to send (not including the file name).
        • sourceFile — Name of the file to send.
        • targetRepo — Target repostiory of the file.
        • targetPath — Path of the resulting file in the target repo (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 systems default timeout.
        • 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.
          • E.g. SendFile("/EdgeDirectory", "test.txt", "MyRepository", "/", "movedFile.txt",  10000,  true);
  • From Composer, bring in the Remote Service on the SteamSensor thing and execute it. Files can now be transferred to or from the .NET SDK
Comments

Has anybody tried this and made it work? GetFile fails for me no matter what parameters I set.

Version history
Last update:
‎Dec 10, 2015 06:17 PM
Updated by:
Labels (1)