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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

EMS - File transfer from LSR device to Thingworx

jknorr
6-Contributor

EMS - File transfer from LSR device to Thingworx

I have a LSR device that is connected to a EMS gateway. The EMS communicates with ThingWorx.
Is it possible to transfer files from the LSR device to a repository in the ThingWorx Platform or can you
just transfer files that are located at the device where the EMS is executed?

ACCEPTED SOLUTION

Accepted Solutions
supandey
19-Tanzanite
(To:jknorr)

Hi @jknorr file transfer is configured and done by EMS, LSR doesn't have direct access to ThingWorx anyhow.

 

If you have files existing on a different server than the EMS, you could still configure the virtual folders in the EMS configuration to transfer those files. 

 

Please feel free to correct me if i got your question wrong.

 

View solution in original post

2 REPLIES 2
supandey
19-Tanzanite
(To:jknorr)

Hi @jknorr file transfer is configured and done by EMS, LSR doesn't have direct access to ThingWorx anyhow.

 

If you have files existing on a different server than the EMS, you could still configure the virtual folders in the EMS configuration to transfer those files. 

 

Please feel free to correct me if i got your question wrong.

 

berik
4-Participant
(To:jknorr)

I think it is possible, though one could argue about the meaning of the LSR transferring, because the EMS is doing the actual transfer. The code below sends an http post command to the EMS to initiate the transfer.

 

-- Copies files from the edge to the server
-- Limitation - Hard coded folder for file target
function copyFileToServer(filename)
 
  local xferjson = json.encode({
  sourceRepo = <name of my remote thing>,
  sourcePath = "/out/", -- this is the output directory configured in your config.json file.
  sourceFile = filename,
  targetRepo = <name of your file repository on the server>,
  targetPath = "/", -- path within the file repository
  targetFile = filename,
  timeout = 600}) -- time allowed to elapse until the ems will timout the file transfer
-- and stop the transfer. It will leave the file in a state with a name of
-- "myfile.txt.part". It can pick up from where it left off if resent.

  local myheaders = {}
  local resp, code
  myheaders["Content-Type"] = "application/json"
  myheaders["Authorization"] = "Basic "..tw_utils.base64_encode("user:password") -- needed if you use http_server authentication in config.json
  resp, code = ps_http.post("127.0.0.1", myData["httpPort"],   "/Thingworx/Subsystems/FileTransferSubsystem/Services/Copy", xferjson, myheaders)
  log.trace("resp", resp)
  log.trace("code", code) -- http post response code. 200 is good.
  log.info("Finished post", filename) --this is really an async transfer, so this is just saying that post
-- was called. This doesn't mean that the file transfer has completed.
end
Announcements


Top Tags