Avatar of adimit19
Flag for Canada asked on

CURL GET Raw File from BitBucket Repository with security

I am trying to get a raw file from a bitbucket repository using curl with the following commands:

curl  -L -O  https://user:password@bitbucket.org/username/repository/branch/HEAD/filename.txt
curl  -L -O  https://user:password@bitbucket.org/username/repository/branch/raw/filename.txt

I have a file committed to the master branch called filename.txt

I want to get the raw version of the above file. What code do i need to get that? All I get from these commands is the HTML code that the page contains
* CurlHTML* terminal* Bitbucket

Avatar of undefined
Last Comment

8/22/2022 - Mon
David Favor

URL embedded user/pass credentials haven't worked for years, so won't work on modern Apache installs.

You'll use something similar to this...

curl --digest --user <username>:<password> https://bitbucket.org/<username>/<repository>/get/<branchname>.zip -o <branchname>.zip

Open in new window

The exact form will vary slightly depending on exactly how your repository is setup. Also whether your repository is public/private.

Might be easier to setup an ssh key with an empty passphrase for your repository access.

I can't use --digest --user <username>:<password>. The security info has to be in the https URL because I will be using that URL in another application. I am simply testing it with CURL first.
David Favor

According to BitBucket docs, here's how you can use curl...


You are correct. You must use the REST API for BitBucket access.

Highly unlikely BitBucket allows URL embedded user/pass credentials, as Apache retired this facility years ago.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
Shaun Vermaak

Why curl? Is the repo so big that you do not want to use git?

Hello David/shaun

David: The syntax works except I can't get the raw format of a single file.

Both: I was hoping to use something like filename.txt?raw instead of the commit key or raw url. I really only need the raw version of a single file and I am stuck on that.

Shaun: I can use git or curl, makes no difference to me. In the end this command will go into another application. Typically the curl command uses the syntax supported by the particular feature in the 3rd party app that I am using.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question