Hi all,
I am new to Bitbucket and am trying to use PowerShell to download a file from the Bitbucket repository. The downloaded file is throwing the below error. Can someone help me with the same.
Below is the code.
clear;
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force
# Define your Bitbucket credentials
$username = "username"
$password = "password"
# Convert credentials to Base64
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
# Define the Bitbucket URL of the file you want to download
$bitbucketUrl = "gitbucket link to the file"
# Define the local path where you want to save the downloaded file
$localPath = "C:\Temp\Download\usp_GetTableColumns.sql"
# Download the file using Invoke-WebRequest with authentication headers
Invoke-WebRequest -Uri $bitbucketUrl -OutFile $localPath -Headers @{ Authorization = "Basic $base64AuthInfo" }
# Check if the file was downloaded successfully
if (Test-Path $localPath) {
Write-Host "File downloaded successfully to: $localPath"
} else {
Write-Host "Failed to download the file."
}
Hi Shravan,
May I know what the $password variable is referring to? We no longer support username/password authentication, so you will need to use App Password for authentication if you are not already doing so.
Cheers!
- Ben (Bitbucket Cloud Support)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.