CURL GET Raw File from BitBucket Repository with security

Viewed 10065

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

4 Answers

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."

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>

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.

Related