Only bit I can see there is that if it errors it will reopen an internet connections and ftp connection, without closing the previous ones.

Might be something there?
Instead of looping back, display an error msg and exit closing off and see if the problem still occurs.

Secondly. remark out all the ftp part and see if it still works fine, then add in the internet connection and the ftp connection.