FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
02-08-2024 09:27 AM
Hello,
I am trying to get .bin files from PLC to PC. Currently I can do so with usage of FB IL_FTPPutFileAsync (from CXA_SocketComm library). Which means initiate data transfer from PLC (client) to PC (server).
But my question is, is it possible to initiate data transfer from PC (specifically with Python)? Should it be possible with FTP or with WebDAV e.g.?
I have read a lot of similar topics so sorry for asking question again, but I haven't found clear answer for initiating that kind of data transfer from PC.
Thanks a lot for your support.
Solved! Go to Solution.
02-08-2024 09:51 AM
There are no FTP server in the core, but it's possible to send a file from a PC to a core via WebDAV, for instance WinSCP as described in this post:
Another way is to have a file share on the Windows PC, and in the core have a Node-RED flow that scans for new files in a folder on the share, and then automatically copy files from the PC to the core from Node-RED.
https://flows.nodered.org/node/node-red-contrib-smb
But there is also another ways to do this, is it only text files they can be sent via the rest api to a PLC variable.
Its also possible to upload a file to the app data in the core using the REST interface.
So it mosly depends what's the application.
02-08-2024 12:55 PM
Thanks. But my goal is to get files from PLC to PC, and use PC as initiator of this data transfer.
In my application I would like to use python script to do all the work, like get files and then work with them.
Firstly I was thinking about ftp, because in CXA_SocketComm documentation is mentioned this:
It should mean that there is running server. Also when I tried to connect to it with FileZilla client it says "Connection refused by server", so if I am not mistaken, than there is some server running, no? But I didn't find any way, how to connect to it and use it.
So shouldn't it be possible to initiate file transfer from some PC client or server?
The other way is to use WebDAV. I setup connection between CtrlX CORE and Windows PC via Map network drive as mentioned in the topic mentioned below. Then I am able to work with files directly.
I don't have much experience with WebDAV yet. Is that connection stable? Is that good way to get files from PLC, or is there better way?
Thanks.
02-08-2024 02:38 PM
Do get a file from a core to a PC, you can just use the REST interface like this:
import urllib.request
import ssl
import json
ssl._create_default_https_context = ssl._create_unverified_context
def auth():
head = {
"Content-Type": "application/json",
"Accept": "application/json",
}
body = {
'name': 'boschrexroth',
'password': 'boschrexroth',
}
data = json.dumps(body).encode("utf-8")
req = urllib.request.Request('https://192.168.1.1/identity-manager/api/v2/auth/token', data, head)
with urllib.request.urlopen(req) as f:
res = f.read()
resonse = json.loads(res.decode())
return resonse['access_token']
def download(token, name):
opener = urllib.request.build_opener()
opener.addheaders = [('Authorization', 'Bearer ' + token)]
urllib.request.install_opener(opener)
urllib.request.urlretrieve("https://192.168.1.1/solutions/files/DefaultSolution/configurations/appdata/" + name, name)
token = auth()
download(token, 'configuration.json')
Modify the IP-adress and filenames according to your settings.
This can download files from the APP data folders of the core, in the example above the configuration.json file: