Skip to content

Instantly share code, notes, and snippets.

@atruskie
Created April 10, 2019 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atruskie/04f009921c002cbf06422c2c2435600d to your computer and use it in GitHub Desktop.
Save atruskie/04f009921c002cbf06422c2c2435600d to your computer and use it in GitHub Desktop.
Purposely corrupt a file for testing reasons (on Unix)

I'm testing file transfer methods (particularly to a SFTP remote).

In particular FileZilla does not detect corrupted files.

Use the above script to corrupt a remote file as a test.

If you are transferring files with rclone (https://rclone.org/) using the --checksums argument it will detect the fault and re-transfer the corrupt file.

FileZilla will twiddle its thumbs

#!/usr/bin/env bash
read -p "Are you sure you want to purposely corrupt $1? " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo "Did nothing, quit"
exit 1
fi
# do dangerous stuff
OLD_DATE=$(date -R -r $1)
echo -n "CORRUPT" | dd of="$1" bs=1 count=7 seek=1024 conv=notrunc
touch -d "$OLD_DATE" -m "$1"
echo "Corrupted $1 at byte 1024"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment