protected function downloadToTempLocalPath($url, $localPath)
    {
        try {
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            $rawFile = curl_exec($ch);
            curl_close($ch);

            if (false === $rawFile) {
                throw new CouldNotRetrieveRemoteFileException(
                    "curl_exec failed while downloading '{$url}': " . curl_error($ch)
                );
            }

        } catch (Exception $e) {
            throw new CouldNotRetrieveRemoteFileException(
                "Failed to download file content from '{$url}': ",
                $e->getCode(),
                $e
            );
        }

        try {
            if (false === file_put_contents($localPath, $rawFile)) {
                throw new CouldNotRetrieveRemoteFileException('file_put_contents call failed');
            }

        } catch (Exception $e) {

            throw new CouldNotRetrieveRemoteFileException(
                'file_put_contents call threw an exception',
                $e->getCode(),
                $e
            );
        }
    }