Best Method for moving files between Client and Server?

Hello,

I’m currently working on developing a system with an edge client (on a windows tablet) which will be used by someone walking around a plant and documenting quality issues. Part of the documentation will include pictures which are taken using the tablet’s built in camera.

I then have a main ignition gateway which is reading tag values and saving them to a SQL database when prompted.

What I want to do is copy the image files from a shared folder on the tablet, to a folder on the machine running the Main Gateway/SQL database.

I’m aware that it is possible to store the image files in a tag as raw data, but for performance reasons I would prefer to avoid doing this.

Here’s what I’ve been testing in the script console without success:

import shutil

shutil.move("\JLV_ROCKWELL\Users\jlv\Pictures\testfolder\file.jpg",“C:\Users\JLV\Desktop\copy target folder\file.jpg”)

Any help or guidance would be greatly appreciated.

A single backslash will escape the next character. If you want to include backslashes in your paths then you will need to use a double backslash. After fixing that and verifying the paths, the next thing to check is permissions.

Ah I will test that.

Before coming back to this, I tried mapping the file location as a drive on the main server/gateway, and it looks like it will actually find the file there. It seems like the main issues was trying to browse to a network location.

Assuming JLV_ROCKWELL is a hostname, you’ll also need even more backslashes at the front. try:

shutil.move("\\\\JLV_ROCKWELL\\Users\\jlv\\Pictures\\testfolder\\file.jpg","C:\\Users\\JLV\\Desktop\\copy target folder\\file.jpg")

Another option would be to use a message handler to move the files, assuming the Ignition server is connected somehow to the file destination.

In a gateway scoped message handler:

	LOG = system.util.getLogger("filetransfer")
	b = payload["bytes"]
	f = payload["filename"]
	LOG.debug("filename:%s,length:%d"%(f,len(b)))
	system.file.writeFile("C:/files/%s"%f,b,False)

An example of some client code:

f = system.file.openFile(None)
if f:
	import os
	(dirname,filename) = os.path.split(f)
	bytes = system.file.readFileAsBytes(f)
	system.util.sendRequestAsync(project = "playground",messageHandler = "File Transfer",payload = {"filename":filename,"bytes":bytes})

Good luck!

2 Likes