The smaller the piece, the better.
The more flexible the piece, the better.
The more hooks into the guts, the better.
Extract pieces out of your program and put it into a library
Take the FTP, XML parsing and HTML generation code out of the program.