I tried doing this exact same thing and it wasn't as quick/easy as I hoped so I bailed, so first off, thank you for making it, and second, don't worry that its messy at least you got it started and that is the hard part.
That's why the code is so messy. A lot of old code left over from trial/error - and a lot of terrible loops to prevent dual FTP connections (which would error).