DataPower file transfer returns base64

I am using the cURL command below to get the DataPower files from being hosted on a remote Solaris server.

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

The getFile.xml content looks like this.

<?xml version="1.0"?>
    <env:Envelope xmlns:env="">
           <dp:request xmlns:dp="">
              <dp:get-file name="config:///unicenter.cfg"/>


When I run the cURL described above on Solaris, I get a long base64 encoded string. But I want the whole file to be copied over to Solaris.


source to share

1 answer

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

This curl command uses DataPower XML management interface, and they call it that all requests and responses are formatted in XML format. You may not have seen it when the long line was long, but it was wrapped in XML. Here's a sample answer with a small payload:

  <?xml version="1.0" encoding="UTF-8"?>
  <env:Envelope xmlns:env="">
      <dp:response xmlns:dp="">
        <dp:file name="local:///testfile.txt">VGhpcyBpcyBub3QgYW4gYWN0dWFsIGVtZXJnZW5jeS4K</dp:file>


So you have two tasks. First, extract the Base64 string from your 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 the XmlStarlet to extract and OpenSSL to perform Base64 decoding.

Then, loop through the curl output like this:

/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 - "& & echo" is to add a trailing newline, and "fold" is to split the Base64 string into lines. They won't need a thinner Base64 decoder. I just chose "openssl" because most people already have it.



All Articles