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
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."
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.
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>
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.