CURL GET Raw File from BitBucket Repository with security

adimit19
adimit19 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Commented:
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.

Author

Commented:
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 FavorFractional CTO
Distinguished Expert 2018

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

https://developer.atlassian.com/server/bitbucket/how-tos/example-basic-authentication/

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.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

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

Author

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial