You can directly copy files from the Azure VMs by accessing the storage account that provides persistent storage for Azure Cloud Shell.
Step 1: Identify the Azure Cloud Shell Storage Account
Open Azure Cloud Shell:
- Go to the Azure portal and open the Cloud Shell.
- If you have not set up persistent storage for Cloud Shell, it will prompt you to create one. Note the storage account and file share name used.
Locate Storage Account and File Share:
- In the Azure portal, navigate to the "Storage accounts" section.
- Find the storage account associated with your Cloud Shell.
- Within the storage account, navigate to "File shares" and locate the file share being used for Cloud Shell.
Step 2: Access the Storage Account from Your VM
- Generate a Shared Access Signature (SAS) Token:
- In the Azure portal, navigate to the storage account and select "Shared access signature" under the "Security + networking" section.
- Generate a SAS token with appropriate permissions (read, write, list) and note the URL.
- Install AzCopy on Your Azure Windows VM:
- If not already installed, download and install AzCopy on your VM.
- Download Files Using AzCopy:
- Open a command prompt or PowerShell window on your Azure VM.
- Use AzCopy to copy files from the Cloud Shell storage file share to the VM.
# Example of copying a file from the Cloud Shell storage to the VM
# AzCopy should be installed on your VM. You can download it from https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10
# Variables
$storageAccountName = "<your-storage-account-name>"
$fileShareName = "<your-file-share-name>"
$sasToken = "<your-sas-token>"
$destinationPath = "C:\path\to\destination"
# AzCopy command to copy files
azcopy copy "https://$storageAccountName.file.core.windows.net/$fileShareName?<sas-token>" $destinationPath --recursive
Step 3: Mount the Azure File Share Directly (Alternative Method)
- Mount the Azure File Share on the VM:
- Instead of using AzCopy, you can directly mount the Azure File Share to the VM as a network drive.
# Variables
$storageAccountName = "<your-storage-account-name>"
$fileShareName = "<your-file-share-name>"
$sasToken = "<your-sas-token>"
$driveLetter = "Z"
# Mount the file share
New-PSDrive -Name $driveLetter -PSProvider FileSystem -Root "\\$storageAccountName.file.core.windows.net\$fileShareName" -Persist -Credential (New-Object PSCredential "Azure\$storageAccountName", (ConvertTo-SecureString $sasToken -AsPlainText -Force))
- Copy Files Using File Explorer or Command Line:
- Once the file share is mounted, you can use File Explorer or command line tools (like
copy
orxcopy
) to transfer files from the mounted drive to the local filesystem on the VM.
- Once the file share is mounted, you can use File Explorer or command line tools (like
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin