I am trying to download the java jdk using powershell scripting as given in the link below
. Here as the author has specified , if I Change the source url where the latest jdk is present i.e.,
http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-windows-x64.exe
the content is not getting loaded , only about 6KB gets downloaded . I have a doubt , whether the download limit in powershell script is only 6KB?
Here is the code :
$source = "http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-windows-i586.exe"
$destination = "C:\Download\Java\jdk-7u60-windows-i586.exe"
$client = new-object System.Net.WebClient
$client.DownloadFile($source, $destination)
EDIT: here's the reason for your problem: you can't directly download the file without accepting the terms before.
I'm using the following script to download files. It's working with HTTP as well as with FTP. It might be a little overkill for your task because it also shows the download progress but you can trim it untill it fits your needs.
After needing this script for a platform installer that required the JDK as a dependency:
Works in PowerShell 6.0 (Hello 2019!) Required a minor fixup to the regex and the way the -imatch line scan happened. Workaround to follow 302 redirects was located here: https://github.com/PowerShell/PowerShell/issues/2896 (302 redirect workaround by fcabralpacheco readapted to get Oracle downloads working again !
This solution downloads 8u201 for Windows x64 automatically.
Since the accepted comment is not working anymore and I cannot comment, I will leave my method here. I modified @steve-coleman's answer by making it scan the page for download links that start with
https
instead ofhttp
. Also I needed to modify$Response
to have a-UseBasicParsing
flag as I was using a headless Windows Server. All in all the script I used was:As usual, YMMV, especially if Oracle change their website.
I modified Robert Smith's answer as follows to get SDK 8u211
Had to change the line -split "
n" | ForEach-Object {
to -split '\r?\n' | ForEach-Object { `And the line If ($_ -imatch '"filepath":"(https://[^"]+)"' {
to If ($_ -imatch '"filepath":"(https://[^"]+)"') {
But in the jkd-8u211-windows-x64.exe file I see
Not sure what to do next. Also added a bit of debug jazz like #echo "$i : $_" >> Oracle.html ...
I got this here and all credit goes to him.... http://dille.name/blog/2016/06/21/running-minecraft-in-a-windows-container-using-docker/
https://github.com/nicholasdille/docker
It works and downloads the Java files.
On inspecting the session on oracle site the following cookie catches attention:
oraclelicense=accept-securebackup-cookie
. With that in mind you can run the following code: