FTP and/or RIO (module) connection problem

I wrote a script to download a bunch of files from an FTP site and it
uses the module RIO to actually copy it to the HD. And every random
amount of files the script gets the error “An established connection was
aborted by the software in your host machine.” And to try to counter
errors I rescue and call the function again. And it constantly gets that
error from that point until the script ends. Then I can rerun the script
and it works again. I need to know a way around this problem by either
closing the connection completely or reseting some part of the modules
that what ever the script is running that causes that.