Example: Importing and Exporting Files Using an Op Script
Use the Junos XML protocol file-put and file-get operations to move a file to or from a remote server. Especially useful when the remote server sits outside a firewall, these commands move the files using the existing Junos XML protocol stream. This obviates the need to open a separate stream for the file transfer, handle authentication before moving files, and verify that the file transfer service is available.
Exporting Files to a Remote Server
Use the Junos XML protocol file-put operation to transfer files within an existing remote Junos XML protocol connection. The basic syntax for using the file-put command is as follows:
<rpc>
<file-put>
<filename>value</filename>
<encoding>value</encoding>
<permission>value</permission>
<delete-if-exist />
<file-contents>file</file-contents>
</file-put>
</rpc>
The following attributes are used with the file-put command. These attributes can be placed in any order with the exception of the file-contents attribute. The file-contents attribute must be the last attribute used with the file-put command.
- filename—(Mandatory) Within this tag, you include the full or relative file path and filename of the file for export. When you use a relative file path, the specified file path should be relative to the user’s home directory. If the specified file directory does not exist, the system returns a “directory not found” error.
- encoding—(Mandatory) Specifies the type of encoding used. You can use ASCII or base64 encoding.
- permission—(Optional) Sets the file’s UNIX permission on the remote server. For example, to apply read/write access for the user, and read access to others, you would set the permission value to 0644. For a full explanation of UNIX permissions, see the chmod command.
- delete-if-exist—(Optional) If specified, an existing file on the remote server will be overwritten. If this attribute is not set, an error is returned if an existing file is encountered.
- file-contents—(Mandatory) The ASCII or base64 encoded file to be exported to the remote server. This attribute must be the last attribute used.
Importing Files from a Remote Server
The Junos XML protocol file-get operation can be used to transfer files within an existing remote Junos XML protocol connection. Unless otherwise specified by the user, the imported file will be placed in the user’s home directory. The basic syntax for using the file-get command is as follows:
<rpc>
<file-get>
<filename>value</filename>
<encoding>value</encoding>
</file-put>
</rpc>
The following attributes are used with the file-get command.
- filename—(Mandatory) Within this tag, you include the full or relative file path and filename of the file for import. When you use a relative file path, the specified file path is relative to the user’s home directory.
- encoding—(Mandatory) Specifies the type of encoding used. You can use ASCII or base64 encoding.
![]() | Note: When you use ASCII encoding, the file-get operation converts any control characters in the imported file to the Unicode character 'SECTION SIGN' (U+00A7). |
Hide Navigation Pane
Show Navigation Pane
Download
SHA1
