I am encountering an issue with AzCopy where my script runs perfectly fine in CMD but fails with authentication errors when executed via a batch file. Here's a breakdown of the situation:
The aim is to get our daily files backed up into storage account via task scheduler; most likely only 1 file per day/run.
My Batch Script:
@echo off
cd "C:\Program Files\AzCopy"
azcopy cp "G:\Backup\UATBackups\*" "https://<storage-account-name>.blob.core.windows.net/test/?sp=rw&st=2024-10-08T15:28:58Z&se=2024-10-08T23:28:58Z&spr=https&sv=2022-11-02&sr=c&sig=<SAS-token>" --recursive=true --block-blob-tier=Cold --overwrite=false
When I Run This Command Manually in CMD: (after navigating to the AzCopy directory)
azcopy cp "G:\Backup\UATBackups\*" "https://<storage-account-name>.blob.core.windows.net/test/?sp=rw&st=2024-10-08T15:28:58Z&se=2024-10-08T23:28:58Z&spr=https&sv=2022-11-02&sr=c&sig=<SAS-token>" --recursive=true --block-blob-tier=Cold --overwrite=false
It works perfectly, and all the files are uploaded as expected.
However, When I Run the Batch File, I Get:
RESPONSE Status: 403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
I also tried modifying the batch file so it opens CMD and runs the command as if I was doing it manually:
start cmd /k ""C:\Program Files\AzCopy\azcopy.exe" cp "G:\Backup\UATBackups\*" "https://<storage-account-name>.blob.core.windows.net/test/?sp=rw&st=2024-10-08T15:28:58Z&se=2024-10-08T23:28:58Z&spr=https&sv=2022-11-02&sr=c&sig=<SAS-token>" --recursive=true --block-blob-tier=Cold --overwrite=false"
But this gives me:
RESPONSE 401: 401 Server failed to authenticate the request. Please refer to the information in the www-authenticate header.
ERROR CODE: NoAuthenticationInformation
Things I Have Checked:
- The SAS Token is valid and not expired.
- The VM time is correctly synced.
- I’m using the same user account to run both the CMD and the batch file.
My Question:
- Why does the command work perfectly when I run it manually in CMD, but fail with a 403 error when run via a batch file (even using the same user account)?
- What needs changing and how do I fix this!
Any help or suggestions would be greatly appreciated. Thanks!