Using OpcCmd Utility for OPC UA File Transfer
If you execute the commands listed in the tutorial below, you will get an overview of basic operations that can be made with an OPC UA Server that provides OPC UA File Transfer model:
- Accessing a standalone OPC UA file node, and accessing an OPC UA file system.
- Getting file properties (metadata).
- Saving file contents to a local operating system file.
- Loading file contents from a local operating system file.
- Clearing directory contents.
- Creating a subdirectory in the OPC UA file system.
- Copying files in the OPC UA file system.
- Displaying contents of a directory in OPC UA file system in a table or as a tree.
- Deleting a file from OPC UA file system.
This tutorial works with Unified Automation UA .NET SDK Bundle server. You should be able to use the principles explained in this tutorial with other OPC UA servers that provide the File Transfer model, by modifying the relevant parameters used in the commands.
- Start the Unified Automation UA .NET SDK Bundle server, by typing
- Start the OpcCmd utility in interactive mode. The interactive mode is always in effect e.g. when you use ClickOnce, or when running the utility from QuickOPC Launcher/Start menu. In other cases, you need to use the
--interactive) option on the command line.
- At the OpcCmd> prompt, enter , or shortened: . This command tells the utility that from now on, we will be accessing the File Transfer functionality of OPC UA. The programs responds with a confirmation of the command.
Subsequent commands are entered at the uaFileTransferClient> prompt. You can enter
--help(possibly preceded by the command name) at any time to obtain help for this prompt (or its commands).
- In order to access a file that is represented by a standalone node in the server (i.e. not part of the OPC UA file system), enter
getFileInfocan be shortened to
--readOnlycan be shortened to
-ro). The node Id used in this command refers to a predefined node in the server which contains a demo text file. The
--readOnlyoption tells OpcCmd that we do not intend to make (and do not want to allow) any modification to the file metadata or contents inside the OPC UA server (this is optional).
Subsequent commands are entered at the fileInfo> prompt.
- Display the file properties by entering
- The OpcCmd Utility will now ask you whether you want the client to trust the server certificate. Verify that that you have been presented with the right server server certificate, and if so, accept the certificate by pressing
After the certificate is accepted, the
getcommand proceeds. If OpcCmd is set to the "OPC compliance" mode, in which the secure connections are the default, and this is the first operation made from this client on the server, you will most likely receive file properties where the relevant values (such as file length, and last modified date) will be missing. This is caused by the fact that the server does not trust the client. In order to establish the trust:
- The Unified Automation UA .NET SDK Bundle server will show the rejected client certificate on the "Rejected Certificates" tab of its window. On this tab, locate the rejected OpcCmd application certificate, right-click on it and select "Trust Permanently"; when asked, confirm the operation.
- Enter the
- Save the contents of the OPC UA file to a file in your local file system by entering
- Enter uaFileTransferClient> prompt.
- In order to access the file system in the OPC UA server (a hierarchical structure consisting of file and directories), enter
getDirectoryContentscan be shortened to
--EndpointUsercan be shortened to
-eu). The node Id used in this command refers to a predefined node in the server which contains a root of the file system (different servers will use a different node, and there can be multiple file system in an OPC UA server). This command also specifies user name and password, because we will be doing modifications to the file system, and the server requires user authentication for such operations.
Subsequent commands are entered at the directoryContents> prompt.
- In order to remove all files and directories from the file system, enter
- Create a file named 'MyTestFile.txt' in the root directory of the OPC UA file system and load it with the data from the existing file that we have previously saved to the disk, by entering
, or shortened: . Use the path to your local file that you have used in the tutorial step with the
- To display the list of files and directories under the current directory (file system root), enter
- Create a subdirectory named 'MyTestDirectory' in the root directory, by entering
- Copy the file 'MyTestFile.txt' from the root directory to the 'MyTestDirectory' directory and give it a name 'CopyOfMyTestFile.txt', by entering
- To display a tree of the objects currently in the file system, enter
- In order to delete the 'CopyOfMyTestFile.txt' file from 'MyTestDirectory', enter
Other OPC UA File Transfer operations that can be made using OpcCmd, but not shown in this tutorial, include:
- Moving and renaming files.
- Refreshig file metadata information.
- Accessing subdirectories.
- Deleting directories.
- Moving and renaming directories.
- Saving contents of whole directory trees to the local file system.
- Loading contents of whole directory trees from the local file system.
Comparison with Windows and Linux commands
Commands at the directoryContents> prompt:
|Change current directory||chdir <path>||(tbd)||directoryContents <path>|
|Clear the current directory||(tbd)||(tbd)||clear|
|Clear the specified directory||(tbd)||(tbd)||directoryContents <path> clear|
|Copy a directory tree||xcopy /e <source> <destination>||(tbd)||directoryContents <source> copyTo <destination>|
|Copy a file||copy <source> <destination>||(tbd)||fileInfo <source> copyTo <destination>|
|Create a directory||mkdir <path>||(tbd)||createSubdirectory <path>|
|Delete a directory||rmdir <path>||(tbd)||directoryContents <path> delete|
|Delete a file||erase <fileName>||(tbd)||fileInfo <fileName> delete|
|Display current directory contents||dir||(tbd)||filesInfos?|
|Display specified directory contents||dir <path>||(tbd)||directoryContents <path> filesInfos?|
|Move a directory||move <source> <destination>||(tbd)||directoryContents <source> moveTo <destination>|
|Move a file||move <source> <destination>||(tbd)||fileInfo <source> moveTo <destination>|
|Obtain file information||(tbd)||(tbd)||fileInfo <fileName> get|
|Rename a directory||rename <oldDirectoryName> <newDirectoryName>||(tbd)||directoryContents <oldDirectoryName> rename <newDirectoryName>|
|Rename a file||rename <oldFileName> <newFileName>||(tbd)||fileInfo <oldFileName> rename <newFileName>|