Friday, February 12, 2010

I want to copy those files! – A tale on how to get files from a “locked down” virtual machine over RDP

I recently attended a course where we first connected to a virtual machine thru a custom application, then connected to the VM via RDP.

The VM had a folder full of lab exercises which would be nice to have locally for reference. But how could I move these files? The VM’s were not on internet so file transfer to a repository on the internet was out of the questions.

Mapping up local drives were also blocked, which it should for security reasons. The only available mechanism which carried data back and forth from my local machine to the VM was the clipboard.

An idea is born!

Since this was a developers course and we had Visual Studio available it was actually a no brainer.

  1. Zip up the labs folder in explorer
  2. Run the following code:
    static void Main(string[] args)
    string base64 = Convert.ToBase64String(File.ReadAllBytes(@"C:\Student\"));
    File.WriteAllText(@"C:\Student\labs.txt", base64);
  3. Open up the base64 encoded file in visual studio
  4. Copy the content to the clipboard
  5. Paste the clipboard to a text file locally
  6. Run the following code to decode it all:
    static void Main(string[] args)
    string base64 = File.ReadAllText(@"c:\temp\labs.txt");
    File.WriteAllBytes( @"c:\temp\", Convert.FromBase64String(base64) );
Presto, and the lab files were transferred.