Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download directory from private github repo using wget

Tags:

git

curl

wget

Is there a way to do this using only wget (or curl or some other linux terminal command)? Git is not installed on the machine from which this command will be run.

Currently I am being given a 404 Not Found error when I attempt to download the lib folder of my repo by running this command:

wget --header="Authorization: token {token}" -r https://raw.githubusercontent.com/{user}/{repo}/{branch}/{path to builds dir}/lib

The directory definitely exists and the following code downloads a file from within the directory just fine:

wget --header="Authorization: token {token}" --output-document={file}.jar https://raw.githubusercontent.com/{user}/{repo}/{branch}/{path to builds dir}/lib/{file}.jar
like image 882
wesrobin Avatar asked Nov 10 '22 19:11

wesrobin


1 Answers

This is the solution you'll need if you want to accomplish this task programmatically. And this is actually what DownGit is using under the hood. Using GitHub's REST API, write a script that does a GET request to the content endpoint. The endpoint can be constructed as follows: https://api.github.com/repos/:owner/:repo/contents/:path. After replacing the placeholders, an example endpoint is: https://api.github.com/repos/babel/babel-eslint/contents/lib. This gives you JSON data for all of the content that exists in that folder. The data has everything you need, including whether or not the content is a folder or file, a download URL if it's a file, and an API endpoint if it's a folder (so that you can get the data for that folder). Using this data, the script can recursively go through all content in the target folder, create folders for nested folders, and download all of the files for each folder. Check out DownGit's code for inspiration.

like image 63
Prateek Paranjpe Avatar answered Nov 15 '22 04:11

Prateek Paranjpe