'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 (I have tried many but I am including the last two):
curl -L -O https://user:[email protected]/username/repository/branch/HEAD/filename.txt
curl -L -O https://user:[email protected]/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
Solution 1:[1]
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."
Solution 2:[2]
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>
Solution 3:[3]
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.
Solution 4:[4]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | tobias |
Solution 2 | oravecz |
Solution 3 | Arthur |
Solution 4 | vp venks |