4 Replies Latest reply on Oct 14, 2016 5:05 AM by ses RSS
    ses Apprentice

    Transfer file from TW Server to remote JavaSDK

    Hi Experts, Coluld you pls guide me on steps for

    Transfer a file(zip) from TW Server to remote JavaSDK


    I tried something, but not succeeded, using Copy service.

    With that I cud achieve only copy a file between two folders, both on the TW Server.

    My need is to copy a file from TW Server to remote JavaSDK.



      • Re: Transfer file from TW Server to remote JavaSDK
        meghan Communicator



        You are correct in using the Copy service, but there are a couple of things you need to make sure are configured correctly:


        • A FileRepository Thing has been created on the ThingWorx server - in the following code sample (from a custom service) I've named my FileRepository "TestingRepo"
          • sourceRepo is the name of my FileRepository in ThingWorx
          • targetRepo is the name of the Edge Thing defined in the Java SDK

        var params = {

          async: false /* BOOLEAN */,

          sourceRepo: "TestingRepo" /* STRING */,

          targetRepo: "FileTransferExample" /* STRING */,

          targetFile: "werd_2014.gif" /* STRING */,

          targetPath: "in" /* STRING */,

          sourceFile: "werd_2014.gif" /* STRING */,

          sourcePath: "Meghan" /* STRING */,

          timeout: undefined /* INTEGER */



        // result: INFOTABLE dataShape: FileTransferJob

        var result = Subsystems["FileTransferSubsystem"].Copy(params);

        • The following is the entire Java file (provided in the Java SDK download) that sets up Virtual Directories for a file transfer.
          • If you look at the custom service above to see that we are referencing the targetPath for a directory that is defined in the Java class.

        package com.thingworx.javatransfer;


        import com.thingworx.communications.client.ClientConfigurator;

        import com.thingworx.communications.client.ConnectedThingClient;

        import com.thingworx.communications.client.things.filetransfer.FileTransferVirtualThing;



        public class FileTransferExample {


          // Substitute your thing name here

          private static final String ThingName = "FileTransferExample";


          public static void main(String[] args) {


          // Create a client config

          ClientConfigurator config = new ClientConfigurator();


          // Basic configuration. See SimpleClient.java for additional info.





          try {

          ConnectedThingClient client = new ConnectedThingClient(config);

          FileTransferVirtualThing myThing = new FileTransferVirtualThing(ThingName, "File Transfer Example", client);


          // Add two virtual directories that will act as the root directories in this

          // application's virtual file system.

          myThing.addVirtualDirectory("in",  "/home/meg/files/in");

          myThing.addVirtualDirectory("out", "/home/meg/files/out");





          while(!client.isShutdown()) {




          } catch(Exception e) {






        Let me know if you have any further questions.