Dave Ceddia
Dave Ceddia

Reputation: 1490

How can I download a single raw file from a private Bitbucket repo using the command line?

I'd like to download a file from a private repo without cloning the whole thing.

All of the results I can find suggest the same thing: create an App Password in Bitbucket, then use that password along with your username. I tried it:

curl -u my_username:app_password https://bitbucket.org/my_username/the_repo/raw/commit_sha/the_file

I know the URL is at least reasonable because I can view it in a browser if I'm logged into Bitbucket.

But running the curl command fails with an error:

Bitbucket Cloud recently stopped supporting account passwords for API authentication.
See our community post for more details: https://atlassian.community/t5/x/x/ba-p/1948231
App passwords are recommended for most use cases and can be created in your Personal settings:
https://bitbucket.org/account/settings/app-passwords/
For more details on API authentication methods see our documentation:
https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication

The second link mentioned has a section about App Passwords that doesn't say much about how to actually use them.

Using the App Password with git clone works fine, but I can't figure out how to get it to work with curl.

Upvotes: 2

Views: 3444

Answers (2)

user22239725
user22239725

Reputation: 1

The Only url which will work to download single file from bit-bucket is this.

Syntax:

curl -L -o output.txt -u username:password "https://api.bitbucket.org/2.0/repositories/username/repo/src/branch/path/to/file.txt"

Example: File downloaded successfully -Command Ran below

[Mon Jul 17 10:24:59 jenkins@5e06d0d3b9b0:jenkins_server:192.168.0.7:~/ansible-scripts ] $ curl -L -o output.txt -u abhilash-jain:ATBBXpY5ZSw-test-password-8H7923C50D "https://api.bitbucket.org/2.0/repositories/abhilash-jain/abhi-test1/src/main/help.txt"

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 27 100 27 0 0 25 0 0:00:01 0:00:01 --:--:-- 25 [Mon Jul 17 10:28:30 jenkins@5e06d0d3b9b0:jenkins_server:192.168.0.7:~/ansible-scripts ] $

Upvotes: 0

Bill Craun
Bill Craun

Reputation: 905

This works for me:

curl -u <user>:<app_password> -L -O https://api.bitbucket.org/2.0/repositories/<org>/<repo>/src/<branch>/<file>

Bitbucket REST API docs

Upvotes: 4

Related Questions