I strongly recommend going with rsync instead of rolling your own code. Often the most important lesson for programmers - and the hardest - to learn is the value of researching existing wheels before setting out to build your own. Often there is no way that the home-cobbled one will match the solid ones already in mass-production, no assembly required...