diff --git a/src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py b/src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py index d78b1a30fbe..4abdc96c4f2 100644 --- a/src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py +++ b/src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py @@ -60,12 +60,20 @@ def install_azcopy(self, install_location): if self.system == 'Windows': if platform.machine().endswith('64'): file_url = base_url.format('windows', 'amd64', AZCOPY_VERSION, 'zip') + if _verify_url(file_url) is None: + file_url = _verify_url('https://aka.ms/InstallAzCopyForCLIWindowsX64') else: file_url = base_url.format('windows', '386', AZCOPY_VERSION, 'zip') + if _verify_url(file_url) is None: + file_url = _verify_url('https://aka.ms/InstallAzCopyForCLIWindows') elif self.system == 'Linux': file_url = base_url.format('linux', 'amd64', AZCOPY_VERSION, 'tar.gz') + if _verify_url(file_url) is None: + file_url = _verify_url('https://aka.ms/InstallAzCopyForCLILinux') elif self.system == 'Darwin': file_url = base_url.format('darwin', 'amd64', AZCOPY_VERSION, 'zip') + if _verify_url(file_url) is None: + file_url = _verify_url('https://aka.ms/InstallAzCopyForCLIDarwin') else: raise CLIError('Azcopy ({}) does not exist.'.format(self.system)) try: @@ -74,8 +82,10 @@ def install_azcopy(self, install_location): os.chmod(install_location, os.stat(install_location).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) except OSError as err: + azcopy_install_guide = 'https://learn.microsoft.com/azure/storage/common/storage-use-azcopy-v10' raise CLIError('Connection error while attempting to download azcopy {}. You could also install the ' - 'specified azcopy version to {} manually. ({})'.format(AZCOPY_VERSION, install_dir, err)) + 'specified azcopy version to {} manually following the guide here: {} ' + '({})'.format(AZCOPY_VERSION, install_dir, azcopy_install_guide, err)) def check_version(self): try: @@ -218,6 +228,7 @@ def _get_default_install_location(): def _urlretrieve(url, install_location): import io + logger.warning('Downloading AzCopy from %s', url) req = urlopen(url) compressedFile = io.BytesIO(req.read()) if url.endswith('zip'): @@ -235,3 +246,15 @@ def _urlretrieve(url, install_location): f.write(tar.extractfile(tarinfo).read()) else: raise CLIError('Invalid downloading url {}'.format(url)) + + +def _verify_url(url): + from urllib.error import HTTPError, URLError + try: + response = urlopen(url) + if response.code == 200: + return response.url + return None + except (HTTPError, URLError): + logger.warning('There is an error downloading from the url: %s', url) + return None