Using OpcCmd Utility for OPC UA File Transfer: Difference between revisions
No edit summary |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category:OPC UA]] [[Category:OPC UA File Transfer]] [[Category:OpcCmd Utility]] [[Category:Tools and Online Services]] | [[Category:OPC UA]] [[Category:OPC UA File Transfer]] [[Category:OpcCmd Utility]] [[Category:Tools and Online Services]] | ||
For general information about the OpcCmd tool, see [[:Category:OpcCmd Utility]]. | For general information about OPC UA File Transfer, see [[OPC UA File Transfer concepts]]. For general information about the OpcCmd tool, see [[:Category:OpcCmd Utility]]. | ||
= Tutorial = | = Tutorial = | ||
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: | 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: | ||
Line 45: | Line 45: | ||
* Saving contents of whole directory trees to the local file system. | * Saving contents of whole directory trees to the local file system. | ||
* Loading contents of whole directory trees from the local file system. | * Loading contents of whole directory trees from the local file system. | ||
= Comparison with Windows and Linux commands = | |||
(TBD) | |||
Commands at the {{Style=label|directoryContents>}} prompt: | |||
{| class="wikitable" | |||
|- | |||
! Operation !! Windows command<br/>(CMD) !! Linux command<br/>(Bash) !! OpcCmd command<br/>(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> | |||
|} |
Latest revision as of 05:16, 21 May 2021
For general information about OPC UA File Transfer, see OPC UA File Transfer concepts. For general information about the OpcCmd tool, see Category:OpcCmd Utility.
Tutorial
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 UaServerNET.exe at the operating system command prompt, when in the 'bin' directory of the Unified Automation UA .NET SDK Bundle.
- 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
-i
(or--interactive
) option on the command line. - At the OpcCmd> prompt, enter uaFileTransferClient, or shortened: uaftc. 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-?
,-h
or--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 getFileInfo opc.tcp://localhost:48030 "nsu=http://www.unifiedautomation.com/DemoServer/ ;s=Demo.Files.TextFile" --readOnly (
getFileInfo
can be shortened togfi
, and--readOnly
can 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--readOnly
option 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 get.
- 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 Y for "Yes".
After the certificate is accepted, theget
command 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 get command again.
- Save the contents of the OPC UA file to a file in your local file system by entering saveTo --osFilePath c:\work\file1.txt, or shortened: st -os c:\work\file1.txt. You can replace the file path (for your operating in system) in the command with a different one, as you need. The directory where you want the file be placed must already exist. Note that an existing file on the disk, if it exists, will be overwritten without confirmation. After the operation is finished, you can use the means of your operating system to view the file.
- Enter exit to return to the uaFileTransferClient> prompt.
- In order to access the file system in the OPC UA server (a hierarchical structure consisting of file and directories), enter getDirectoryContents opc.tcp://localhost:48030 "nsu=http://www.unifiedautomation.com/DemoServer/ ;s=Demo.Files.FileSystem" --EndpointUser john:master (
getDirectoryContents
can be shortened togdc
, and--EndpointUser
can 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 clear or clr. Caution: Before executing the command, make sure the file system does not contain any information you may later need. This step is included in the tutorial so that the file system starts in a defined state, and we can be sure e.g. that the commands will not collide with files or directories created in previous executions of the tutorial. You can skip this step if you can assure that such conflicts won't arise. The command will ask for confirmation; press Y for "Yes".
- 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 fileInfo MyTestFile.txt loadFrom --osFilePath c:\work\file1.txt, or shortened: fi MyTestFile.txt lf -os c:\work\file1.txt. Use the path to your local file that you have used in the tutorial step with the
saveTo
command. - To display the list of files and directories under the current directory (file system root), enter fileInfos?, or shortened: fi?. The table will contain the 'MyTestFile.txt' file that we have created in the previous step.
- Create a subdirectory named 'MyTestDirectory' in the root directory, by entering createSubdirectory MyTestDirectory, or shortened: cs MyTestDirectory.
- Copy the file 'MyTestFile.txt' from the root directory to the 'MyTestDirectory' directory and give it a name 'CopyOfMyTestFile.txt', by entering fileInfo MyTestFile.txt copyTo MyTestDirectory/CopyOfMyTestFile.txt, or shortened: fi MyTestFile.txt ct MyTestDirectory/CopyOfMyTestFile.txt.
- To display a tree of the objects currently in the file system, enter browseTree or bt. At this point, the tree will contain the original 'MyTestFile.txt' file created, and a 'MyTestDirectory' subdirectory with the file copy, 'CopyOfMyTestFile.txt'.
- In order to delete the 'CopyOfMyTestFile.txt' file from 'MyTestDirectory', enter fileInfo MyTestDirectory/CopyOfMyTestFile.txt delete, or shortened: fi MyTestDirectory/CopyOfMyTestFile.txt d.
- Enter browseTree or bt again, and verify that the file from the previous step has been deleted.
Other Operations
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
(TBD)
Commands at the directoryContents> prompt:
Operation | Windows command (CMD) |
Linux command (Bash) |
OpcCmd command (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> |