While trying to create some new plugins for Win10PESE I stumbled about some downloading issues.
Using provided tools such as wget or webget I wasn't able to download files from the EF Software Site via command line.
Site: http://www.efsoftware.com/dw/e.htm.
x64 portable version of EFCommander: http://www.efsoftware.com/dw/wz6.cgi?cw
I see that this site uses java script and it seems that wget is not able to follow them correctly (honestly, I'm guessing only).
Example code line for wget I used before:
SET "_DestDir=%~dp0" 2>NUL
IF "%DestDir:~-1%"=="\" SET "DestDir=%DestDIR:~0,-1%" 2>NUL
SET "_URL=http://www.efsoftware.com/dw/wz6.cgi?cw"
SET "LANG=EN"
SET "LANGUAGE=EN"
SET "TSTAMP=-N"
SET "VERBOSENESS=-v"
SET "TRIES=--tries=3"
SET "WAITRETRY=--waitretry=2"
SET "CACHING=--cache=off"
%_WGET% %VERBOSENESS% %TSTAMP% %CACHING% %TRIES% %WAITRETRY% "%_URL%" -P"%_DESTDIR%"
In the meantime I tried to "bypass" this issue by calling powershell and bitsadmin.
The code below is what I have so far. It might be of help somehow but some code lines are really clumsy in my eyes.
Could anybody guide me here?
Am I guessing right that wget isn't able to resolve links from sites written with java script?
If No, is this a syntax problem I didn't solve here?
If Yes, are there any other tools (freeware) that are able to download files from this/such site(s)?
Regarding bitsadmin.exe - is it legal to provide this file inside a plugin script encoded via Winbuilder?
Maybe my coding attempts below are reliable alternatives (in general) to external tools that must be downloaded for this specific task?
If so, maybe someone could help to improve code?
EDIT: FileExists section removed - it's completely unneccessary.
Note: Please do not copy the following code to notepad.exe. Use a real text editor instead.
@echo off
SETLOCAL ENABLEEXTENSIONS
SET "_LDir=%~dp0"
IF "%_LDIR:~-1%"=="\" SET "_LDir=%_LDIR:~0,-1%" 2>NUL
SET _LocalFile=%_LDIR%\EFCommander.zip
SET _URL=http://www.efsoftware.com/dw/wz6.cgi?cw
DIR /B "%_LOCALFILE%" >NUL 2>&1 && ECHO File to download already exists... skipping download.&&GOTO:_End
:: check for existance of powershell.exe and set _PS variablepowershell "EXIT ECHO Works" 2>NUL && SET "_PS=1"
:: get PSVersion Major and Minor
CALL:_PSVers _PSVersMaj _PSVersMin
ECHO Powershell engine %_PSVersMaj%.%_PSVersMin% or higher detected.
ECHO Press any key to to download the desired file...& PAUSE>NUL
:: try to download file via Powershell
CALL:_PSDownload "%_LOCALFILE%" "%_URL%"
DIR /B "%_LOCALFILE%" >NUL 2>&1 && ECHO Download successful.&&GOTO:_End
:: check for existance of bitsadmin.exe:: on success - evaluate if bitsadmin.exe supports the /TRANSFER switch
bitsadmin >NUL 2>&1 && SET "_BITS=1" && bitsadmin.exe /?|FIND /I "/transfer " >NUL 2>&1 && SET _BITS=2
:: try to download file via bitsadmin.exe
CALL:_BitsDownload "%_LOCALFILE%" "%_URL%" 15
DIR /B "%_LOCALFILE%" >NUL 2>&1 && ECHO Download successful.||ECHO Download failed
:_End
ECHO This is the END
PAUSE>NUL&EXIT
:: _____________________________________________________________________
:: This code is tested under XP SP3, Win7,Win8.1 and Win10.
:: The PS exitcode command helps to capture integer values via returned
:: errorlevel. PSVersion.Major must be 1 or higher - use errorlevel 1.
:: PSVersion.Minor must be 0 or higher, so use errorlevel 0.
:: Ref:https://blog.jourdant.me/post/3-ways-to-download-files-with-powershell
:: _____________________________________________________________________
:_PSVers VersionMajorOUT VersionMinorOUT
IF NOT DEFINED _PS GOTO:EOF
powershell "Exit $PSVersionTable.PSVersion.Major"
IF ERRORLEVEL 1 SET /A %~1=%ERRORLEVEL%
powershell "Exit $PSVersionTable.PSVersion.Minor"
IF ERRORLEVEL 0 SET /A %~2=%ERRORLEVEL%
GOTO:EOF
:_PSDownload TargetFileIN UrlIN
IF NOT DEFINED _PS GOTO:EOF
SET /P "=Downloading via PS BitsTransfer..." <NUL
powershell "Import-Module BitsTransfer;EXIT Start-BitsTransfer -Source '%~2' -Destination '%~1'" >NUL
:: NET2.0
IF ERRORLEVEL 1 (Echo Errors occured.
SET ERRORLEVEL=
SET /P "=Downloading via PS Net.WebClient..." <NUL
powershell "EXIT (New-Object System.Net.WebClient).DownloadFile('%~2', '%~1')" >NUL
)
:: PS 3.0 or higher
IF ERRORLEVEL 1 (Echo Errors occured.
SET ERRORLEVEL=
IF %_PSVersMaj% GTR 3 (
SET /P "=Downloading via PS Invoke-WebRequest cmdlet..." <NUL
powershell "Invoke-WebRequest '%~2abcd' -OutFile '%~1'" >NUL
)
)
IF ERRORLEVEL 1 Echo Errors occured.
GOTO:EOF
:: __________________________________________________________________________
:: If bitsadmin.exe supports the /transfer switch then everything goes well.
:: Otherwise fall back to commandline syntax that is supported for very early
:: versions [e.g. v1.0.5.1.2600.0 [XPPro SP3] in support\tools\support.cab].
:: In regard to the version mentioned above, I couldn't figure out how to get
:: feedback if a download is completed before using the /COMPLETE switch.
:: Therefore a very clumpsy wait-like command was placed here. Anybody know
:: how to improve/overcome this?
:: __________________________________________________________________________
:_BitsDownload TargetFileIN UrlIN TimeoutIN
SETLOCAL
IF NOT DEFINED _BITS GOTO:EOF
SET "_B=bitsadmin.exe"
SET "_Job=MyJob"
SET "_T=%~3"
%_B% /RESET
IF %_BITS%.==2. (
%_B% /transfer %JOB% /download /priority normal "%~2" "%~1"
) ELSE (
%_B% /CREATE %_JOB%
%_B% /ADDFILE %_JOB% "%~2" "%~1"
%_B% /RESUME %_JOB%
REM %_B% /WRAP /INFO %_JOB% /VERBOSE
REM %_B% /GETCOMPLETIONTIME %_JOB%
ECHO.&ECHO Waiting %_T% seconds to execute /COMPLETE switch...
ping -n %_T% localhost >NUL
%_B% /COMPLETE %_JOB%
)
ENDLOCAL
GOTO:EOF