Some files were uploaded in the wrong mode to the FTP (via command line). I believe I have some binary files that were uploaded in TEXT mode and now I cannot open them.

I dont have access to the original files, can I somehow recover from this? Is there some tool that will allow me to get the files in their correct format?


I recently had to face the same problem. Linux -> Windows, ASCII mode. I've finished writing a program in Python that allows for the recovery of ASCII transferred binaries. It's a byte bruteforcer, and here is how it works:

  1. Open damaged archive as byte stream.
  2. Find all occurrences of 0d followed by 0a (ASCII 13, ASCII 10).
  3. Remove all occurrences of 0d followed by 0a and store the byte addresses.
  4. Cycle through each of the addresses to restore a number of 0d's in case they were supposed to be there in the binary, restore and try to open (in my case I was dealing with bz2 archives, and had a CRC checksum algorithm check the integrity of the uncompressed data and match it with the one hardcoded into the archive).

The number of possible valid 0d 0a byte pairs in a binary will not be very high; the probability of a binary having a valid 0d 0a pair is quite low. The time a bz2 archive takes to fix with this bruteforce method is under 10 seconds for files under 100kb. I have not checked it with other types of files, but it is possible.

I am not going to paste the code here, since this question is not programming related, and this was a sort of competition task and I don't think I'm comfortable with taking the sources public, but if you do require it, please let me know.

Cheers, and Merry Christmas everyone! :)


Knowing whether it's possible to undo the destruction requires knowing the operating systems involved. The consequences depend on what combination of operating systems you use on server and client.

The worst problem is the end-of-line character. Windows use a carriage return (ASCII value 13) followed by a line feed (ASCII value 10) while Linux uses only line feed.

Text mode FTP transfer translates this. Binary mode doesn't. Which is where the destruction comes in.

If the transfer went from Windows to Linux, it would be impossible to determine whether a LF was originally a LF or a combination of CR-LF. As data is lost, undoing the destruction is next to impossible.


As noted by others, the data is corrupted and potentially unrecoverable.

However, 0x0D 0x0A isn't a particularly common sequence of bytes in most binary file formats [citation needed!], so it's worth a try replacing them to see if that fixes the file.

The fixgz utility does just that. Despite it's name, it has nothing specific to .gzip files and can be used on any file.

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.