Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to download a file from private repository using curl

Adam Grzesiczak
Contributor
June 18, 2019 edited

Hi,

Is there a way to download a file from a private repository using curl or wget?

I'm getting a 401 when hitting below URL. The app password got only read permissions to Repository and I wonder if this is enough or the URL is correct. I can't use the RAW file as the URL to RAW version is changing unless there is URL to always get the RAW version of the file?

curl -s -S --user username:apppassword -L -O https://bitbucket.org/<ORG_NAME>/<REPO>/src/master/<FOLDER>/file.txt

In a browser this will display the file and the website itself so it might not be a good way of doing it but I can't find a correct API URL.

Update: I found a correct URL for the latest RAW file but I always get 401 with curl/wget and an apppassword. What permissions app password needs to get this file?

3 answers

5 votes
Adam Grzesiczak
Contributor
June 18, 2019

Ok found a "correct" way to do it. "Correct" as you shouldn't use passwords in a bash like that.

curl -s -S --user username:apppassword -L -O https://api.bitbucket.org/2.0/repositories/<ORGANISATION>/<REPO>/src/master/<FOLDER>/<FILE>
aloraine October 4, 2019

Thanks! I have the same question. This worked for me, as well. 

Adam Grzesiczak
Contributor
April 1, 2020

One way to import passwords to a bash script is from an external file.

 

script.sh

#!/bin/bash

source passwords.txt

curl -s -S --user ${USER}:${APP_PASSWORD} -L -O https://api.bitbucket.org/2.0/repositories/<ORGANISATION>/<REPO>/src/master/<FOLDER>/<FILE>

 

passwords.txt

USER="username"

APP_PASSWORD="password"
1 vote
Charlie Simon
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 6, 2021

Just letting anyone who's curious. Don't use api.bitbucket.org, at least every time I did I was just getting an error. Instead, I've opted to just copy the link to the download from the "Download's" Tab in the repository. Below is my example. 

 

curl -H "Cache-Control: no-cache" --user <Username>:<Password> -L -O https://bitbucket.org/<orgname>/<Repository>/get/<filename>.zip

You'll need to add -H "Cache-Control: no-cache" don't ask me why but setting a custom header seems to solve the problem.


I also removed the silence, just because I like to know I'm not just sitting on a dead page.

 

And if anyone is looking to streamline this. I'm using this as a deployment system via an install.sh script built into a custom ISO with a redirect link to a custom domain that points to the BitBucket download link. Meaning all I need to do is update my URL redirect. I've put below my .sh code in case anyone is curious. It's a neat little trick to save some time in the future.  

Obviously, this will also work within the normal terminal. 

url=$(curl -Ls -o /dev/null -w %{url_effective} <redirect url>)

echo $url

curl -H "Cache-Control: no-cache" --user <Username>:<Password> -L -O $url

0 votes
RogerThomas November 12, 2021

As this thread comes up when trying to research this issue at the end of 2021, here is and example line that works for me, when trying to pull down a file in a public repository

 

curl -s -L https://api.bitbucket.org/2.0/repositories/{workspace)/{repo_name}/src/main/bin/OneLineRoot

 

This pulls down the file /bin/OneLineRoot within the main branch, from repository {repo_name} within the {workspace}.

 

Bitbucket's interface needs to be a lot more exact than say the one presented by github.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, confluence, loom, atlassian intelligence, ai notes, ai-powered meeting notes, atlassian community events, ace, confluence ai, loom ai integration, ai note-taking, atlassian ai features, team '25, atlassian live learning, confluence automation

Unlock AI-powered meeting notes: Join our live learning session! 📹

Did you catch the news at Team ‘25? With Loom, Confluence, Atlassian Intelligence, & even Jira 👀, you won’t have to worry about taking meeting notes again… unless you want to. Join us to explore the beta & discover a new way to boost meeting productivity.

Register today!
AUG Leaders

Atlassian Community Events