The NITRO-API which comes with the Citrix NetScalers offers many possibilities regarding automation, as you can see by checking the various projects on GitHub or in various blogs. Just like the PowerShell Backup Script from my workmate Jens Trendelkamp.

But the need of PSCP for transferring files in this PowerShell Script made me think. So I searched a bit to find a way to download and upload files over the NITRO API and i found something in the Citrix eDocs.

The tricky thing with the NITRO API is, the file handling is based on BASE64 encoded files directly within the payload. But since i thought this is not a problem i created a „Quick & Dirty“ PHP-Function Set to demonstrate that PSCP is not necessary anymore (NetScaler Rocks was a great help at this!).

You will find the Proof of Concept below or in my GitHub Repo.

Please feel free to edit the scripts to an „more efficient & much cleaner“ script.

So lets start the explanation.

config.php – speaks for itself?

functions.php

worker.sample.php

File Download: In the worker script i define the relevant path information, ASCII encoded for the remote filepath on NetScaler. „/var/netscaler/something“ will be „%2Fvar%2Fnetscaler%2Fsomething“. Decode the JSON Output, jump in the „filecontent“ Object and BASE64 decode, create a return value. In the worker script i create the regular file using the function return.

File Upload: Again i define the path information in the worker script. Load the local file, encode it BASE64 and put it in the JSON Payload in fire the POST request.

Thats it!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">