wget – Use to download GitHub files

Background

Let us issue wget to download github files.

Artifacts

  1. EternallyBored.Org
    • Windows binaries of GNU Wget
      Link
  2. SourceForge
    • gnuwin32

Usage

Outline

  1. Download file
    • To download individual files, please use github’s raw interface
  2. Download folder
    • To download entire repository, please use the archive/zip toolset

Tasks

Download File

Syntax


wget [url] 

Sample

Sample – _gitGetFile.cmd

set "_urlBase=raw.githubusercontent.com"
set "_user=DanielAdeniji"
set "_repositoryArchive=visualCPlusPlusErrorAndWarning"

set "_url=%_urlBase%/%_user%/%_repositoryArchive%/%_repositoryFolder%/%_repositoryFile%"

Rem Replace File
set "_option_file_Replace=-r"

set "_optionfile=%_option_file_Replace%"

Rem Progress
set "_option_Progress=--quiet"

Sample – gitGetFileReadMe.md.cmd
setlocal

rem set repository folder and file
set "_repositoryFolder=master"
set "_repositoryFile=README.md"

rem set local Folder
set "_localFolder=backup/online"

rem prepare git source
call _getGetFile.cmd

rem create local folder if it does not exist
if not exist "%_localFolder%" mkdir "%_localFolder%" 

rem invoke wget
wget %_url% -O "%_localFolder%\%_repositoryFile%" %_optionfile% %_option_Progress%

endlocal

Download Repository as a single archive file


setlocal

rem prepare Git source
set "_urlBase=https://github.com"
set "_user=DanielAdeniji"
set "_repositoryBase=visualCPlusPlusErrorAndWarning"
set "_repositoryFolder=archive"
set "_file=master.zip"

set "_url=%_urlBase%/%_user%/%_repositoryBase%/%_repositoryFolder%/%_file%"

rem prepare local folder
set "_localFolder=."
set "_localFolder=backup\online"

Rem Replace File
set "_option_file_Replace=-r"

set "_optionfile=%_option_file_Replace%"

Rem Progress
set "_option_Progress=--quiet"

Rem create local folder if it does not exist
if not exist "%_localFolder%" mkdir "%_localFolder%" 

rem get repository as compressed file (master.zip)
wget %_url% -O %_localFolder%\%_file% %_optionfile% %_option_Progress%

endlocal

Summary

Not too bad.

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s