Cameron Fletcher

Random thoughts and dicussions on the things that interest me

File Transfer via Clipboard Text

I have recently been involved in some work that requires me to program on a Remote Desktop (via RDP over an SSL connection) so there is no development software installed locally. One of the downsides is that due to the restricted nature of the connection only text based copy and paste works, so it is not possible to transfer files onto the development environment. Not only this, but although the local machine has access to the internet, the development environment has none.

The solution? I wrote a console based application called MemCopy to copy files to and from the clipboard as text. It does this by either encoding the file as Base64 then saving it as text on the clipboard, or decoding it from the clipboard.

I'd only written this in one of the environments, so I had to decode it in the other before I could use it - a bit chicken and egg, if you ask me. Anyway, I have attached a link to the encoded text here (you didn't think I was going to give you the solution on a plate did you?)

The code below is all that was required to decode it. I placed the encoding into the resources as a file.

byte[] buffer = Convert.FromBase64String(Resources.Encoding);
FileStream stream = new FileStream("memcopy.zip", FileMode.Create,FileAccess.ReadWrite);
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(buffer);
writer.Close();

For those of you without the technical acumen to decode the above source, I have attached a working copy MemCopy as a zip file here. Simply download and extract MemCopy to a folder of your choosing, copy the contents of the encoded text (above) into memory, then execute MemCopy from the extracted location using the following command:

MemCopy /decode MemCopy.zip

The result? Awesomeness.

Posted: Sep 24 2009, 18:27 by flet0496 | Comments (4) RSS comment feed |
  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .NET

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading