Uploading the contents of a variable using fabric

More than once I needed to create files on the staging/production box which I had no need of on the local development box (For example complex logging configuration). This fragment contains a simple function which tries to do this in a safe manner, and also ensuring proper cleanup in case of failure.