This module provides multiple functions to transfer/download files from a network resource to a local drive.
It also provides ways to download Youtube medias like videos or audio tracks.
Available Download methods
The module currently provides the following download subsystems:
- http : this is using a .NET functionality in PowerShell:
[System.Net.HttpWebRequest]
. It creates a custom https GET request with custom header and writes the returned data on disk. You can use this functioality in both blocking and asynchronous mode. Note that if you start a download in asynchronous mode you can “re-hook” on your download job at anytime to switch to blocking mode and get transfer data information and a progress bar. See example … - bits : this is using PowerShell’s BitTransfer module. When you start a download job with this mode, you get a job managed by the bits service that you can extensively configure.
- bitsadmin : this is also downloading using the Bits service, but the jobs are created and managed using Window’s bitsadmin.exe. Bitsadmin is a command-line tool used to create, download or upload jobs, and to monitor their progress. The bitsadmin tool is useful when the Bits module cannot be installed or used. “bitsadmin”
- wget : this method uses the wget.exe command-line tool. GNU Wget is a free network utility to retrieve files from the World Wide Web using HTTP and FTP. Wget works exceedingly well on slow or unstable connections, keeping getting the document until it is fully retrieved. Re-getting files from where it left off works on servers (both HTTP and FTP) that support it. Wget supports proxy servers, which can lighten the network load, speed up retrieval and provide access behind firewalls.
Download using the BitsTransfer Module
$Parameters = @{
Url = '"https://arsscriptum.github.io/assets/files/ookla-speedtest-1.2.0-win64.zip"'
DestinationPath = "c:\Tmp"
Asynchronous = $False # ASYNCHRONOUS
EnableNotification = $True # NOTIFICATION
Priority = 'High' # Foreground|High|Normal|Low
}
Save-UsingBitsModule @Parameters
NOTE: Notification Option
If you activate the EnableNotification
option. You will get a custom notification after download. I made a custom PowerShell-based message box that will show up along with the Mission Impossible tune.
Download using the bitsadmin.exe commandline tools
$Parameters = @{
Url = '"https://arsscriptum.github.io/assets/files/ookla-speedtest-1.2.0-win64.zip"'
DestinationPath = "c:\Tmp"
Asynchronous = $False
EnableNotification = $True
Priority = 'High' # Foreground|High|Normal|Low
}
Save-UsingBitsAdmin @Parameters
# ASYNCHRONOUS DOWNLOAD
$Parameters = @{
Url = '"https://arsscriptum.github.io/assets/files/ookla-speedtest-1.2.0-win64.zip"'
DestinationPath = "c:\Tmp"
Asynchronous = $True
EnableNotification = $True
Priority = 'High' # Foreground|High|Normal|Low
}
> $CreatedJob = Save-UsingBitsAdmin @Parameters
> ....
# You can get the progress data and switch back to blocking mode by calling `Receive-BitsAdminJob` with the job name $JobName
> Receive-BitsAdminJob $CreatedJob
Download using the wget.exe commandline tools
$Parameters = @{
Url = '"https://arsscriptum.github.io/assets/files/ookla-speedtest-1.2.0-win64.zip"'
DestinationPath = "c:\Tmp"
Asynchronous = $False
EnableNotification = $True
Priority = 'High' # Foreground|High|Normal|Low
}
Save-UsingWGetJob @Parameters
# ASYNCHRONOUS DOWNLOAD
$Parameters = @{
Url = '"https://arsscriptum.github.io/assets/files/ookla-speedtest-1.2.0-win64.zip"'
DestinationPath = "c:\Tmp"
Asynchronous = $True
EnableNotification = $True
Priority = 'High' # Foreground|High|Normal|Low
}
> Save-UsingWGetJob @Parameters
Authentication
In situations where downloading a file requires authentication, you need to add the credential to the HttpClient object. To include a credential to the file download request, create a new System.Net.Http.HttpClientHandler object to store the credentials.
You can copy the code below and run it in PowerShell to test. Or you can also run it as a PowerShell script. In this example, the code is saved as download-file.ps1.
# BLOCKING CALL (will display a progresss bar)
$Parameters = @{
Url = '"https://arsscriptum.github.io/assets/files/ookla-speedtest-1.2.0-win64.zip"'
DestinationPath = "c:\Tmp"
Asynchronous = $False
Authenticate = $True # <==== Authenticate
User = 'me' # <==== USERNAME
Password = 'pass' # <==== PASSSWORD
}
Save-UsingHttpJob @Parameters # will return after completion
# ASYNCHRONOUS DOWNLOAD
$Parameters = @{
Url = '"https://arsscriptum.github.io/assets/files/ookla-speedtest-1.2.0-win64.zip"'
DestinationPath = "c:\Tmp"
Asynchronous = $True
Authenticate = $True # <==== Authenticate
User = 'me' # <==== USERNAME
Password = 'pass' # <==== PASSSWORD
}
> $Ret = Save-UsingHttpJob @Parameters
> ....
# You can get the progress data and switch back to blocking mode by calling `Receive-HttpJob` with the job name
> Receive-HttpJob $($Ret.JobName)
Downloading Youtube Medias using this module
Youtube-dl supports using external downloaders. This can help mitigate artificial throttling that Google appears to be implementing. I found that using aria2 made a massive difference in download speed. To use external downloaders, add the –external-downloader [downloader] option. The list of supported external downloaders is listed in the download options on the github page, but I found it did not work with axel, even though it’s listed.
Here is an example usage:
youtube-dl --external-downloader foobar --external-downloader-args '-a -b- c'
Unfortunately, the implementation is very restrictive in that it supports only a specific set of appliclication, and you cannot use your own. Currently supports aria2c,avconv,axel,c url,ffmpeg,httpie,wget
The rationale of changing the download subsysstem in Youtube-Dl
As mentionned above, using your download subsystem can help mitigate artificial throttling that Google appears to be implementing. You can also really benefit from extended functionalities, especially when downloading big playlists.
BITS
For example, Windows provides a service called the Background Inelligent Transfer Service, this is used to download the Windows Update huge package files and gives the ability to really custommize the way the files are transfered. My main reason for using my own downloader was to use BITS and also use other downloader that provides speed advantages.