3

I am using below cURL command to get DataPower files from applaince to a remote Solaris server.

/usr/local/bin/curl -s --insecure --data-binary @getFile.xml -u username:password https://ip:port/service/mgmt/current

Content of getFile.xml is as below.

<?xml version="1.0"?>
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
      <env:Body>
           <dp:request xmlns:dp="http://www.datapower.com/schemas/management">
              <dp:get-file name="config:///unicenter.cfg"/>
           </dp:request>
      </env:Body>
    </env:Envelope>

When I am running the cURL metioned above on Solaris, I am getting long base64 encoded string. But I wish to get the complete file copied to Solaris.

Chad
  • 1,750
  • 2
  • 16
  • 32
user2607367
  • 225
  • 4
  • 25

1 Answers1

2

The long Base64-encoded string is your file. You need to do a little work to extract it.

This curl command is using the DataPower XML Management interface, and they call it that because all requests and responses are XML-formatted. You may not have seen it as the long string flew by, but it was wrapped in XML. Here's a sample response with a small payload:

  <?xml version="1.0" encoding="UTF-8"?>
  <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Body>
      <dp:response xmlns:dp="http://www.datapower.com/schemas/management">
        <dp:timestamp>2014-10-23T17:12:39-04:00</dp:timestamp>
        <dp:file name="local:///testfile.txt">VGhpcyBpcyBub3QgYW4gYWN0dWFsIGVtZXJnZW5jeS4K</dp:file>
      </dp:response>
    </env:Body>
  </env:Envelope>

So, you have two jobs to do. First, get the Base64 string out of its XML wrapper, and second, decode it. There are a million ways to do this -- I'll give you one of them. Get a copy of XmlStarlet to do the extraction, and OpenSSL to do the Base64 decoding.

Then, pipe the curl output like so:

/usr/local/bin/curl -s --insecure --data-binary @getFile.xml -u username:password https://ip:port/service/mgmt/current \
| (xmlstarlet sel -T -t -v "//*[local-name()='file']" && echo) \
| fold -w 64 \
| openssl enc -d -base64 >this-is-the-real-file

Two quick notes -- the "&& echo" is to add a trailing newline, and the "fold" is to split the Base64 string into lines. A less finicky Base64 decoder wouldn't need these. I just picked "openssl" because most people already have it.

bjimba
  • 928
  • 8
  • 13