4

I am trying to get a raw file from a Bitbucket repository using curl with the following commands (I have tried many but I am including the last two):

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.

Note: Security isn't an issue for this particular usage. I have also tried solutions in the following link: Download private BitBucket repository zip file using http authentication

tobias
  • 934
  • 8
  • 17
A.Dim
  • 51
  • 1
  • 1
  • 2

4 Answers4

4

You almost had it, try the following:

curl -O -u username:password https://bitbucket.org/username/repository/raw/branch/filename.txt

Here is the documentation for curl

  • -O, --remote-name: "Write output to a local file named like the remote file we get. (Only the file part of the remote file is used, the path is cut off.)"

  • -u, --user <user:password>: "Specify the user name and password to use for server authentication."

tobias
  • 934
  • 8
  • 17
  • Thank you for your response. I still don't get the raw file with this call. I get the html source code of the web page. Any other ideas? – A.Dim Jan 16 '19 at 15:14
  • That is strange, I tried my solution earlier with one of my private BitBucket repositories and it worked well with the `README.md` file. Mind trying again ensuring that the path, branch, filename, username and password is correct? Alternatively, what does the HTML source code say? Do you get an error message or anything alike? – tobias Jan 16 '19 at 15:59
3

Not so simple. BitBucket is now returning some HTML markup around the raw content.

<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
...my raw content...
</pre></body></html>
oravecz
  • 1,146
  • 11
  • 16
1

It is quite simple: your URL does point to the web page containing the file. Just choose the URL that is pointing to the "RAW" version of your file (a button in the upper right corner should do the trick), and you will get the proper contents using that URL.

Arthur
  • 11
  • 1
1

curl -o filename -H "Authorization: Bearer Token" https://bitbucket.com/projects/projectname/repos/reponame/raw/filename?at=refs%2Fheads%2FBranchName

Replace the following with yours Token bitbucket.com (URL) projectname reponame filename branchname

This worked for me. Earlier had the issue getting the HTML junk.

vp venks
  • 21
  • 2