Thanks for this Alan. I have tried to solve this problem for weeks for our school which hosts moodle on 'Hostmonster' rather than on my own site on 'Siteground' (which works fine).
I just added the code and it worked for me straight away.
I put it on line 2792 of lib/filelib.php
// All settings of this class should be init here.
$this->resetopt();
$this->options['CURLOPT_IPRESOLVE'] = CURL_IPRESOLVE_V4;
if (!empty($settings['debug'])) {
$this->debug = true;
It also solved a few other problems too e.g. can install plugins from moodle website and checking for updates works every time rather than randomly.
Much appreciated.
Paul