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.

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.

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).