PoshCode Archive  Artifact [1302e9e468]

Artifact 1302e9e4683ff8ee56b904d660f1e668cbb62e251f74e3a88bfd0a5a6ff6cdb4:

  • File CmdWget.ps1 — part of check-in [792fc93274] at 2018-06-10 13:41:04 on branch trunk — This is command line script that invoke cscript by itself to download a file. Just save this code with CMD or BAT extension and lanch, for example, with next way: CmdWget E:\arc http://download.sysinternals.com/files/Autoruns.zip – this allow you to download autoruns.exe tool of Sysinternals into E:\arc directory. Note that directory shoul be exist and you do not need specify name of file which you want to download, script saves file with name that specified in url (url is sensitive for register). (user: greg zakharov size: 2108)

# encoding: ascii
# api: powershell
# title: CmdWget
# description: This is command line script that invoke cscript by itself to download a file. Just save this code with CMD or BAT extension and lanch, for example, with next way: CmdWget E:\arc http://download.sysinternals.com/files/Autoruns.zip – this allow you to download autoruns.exe tool of Sysinternals into E:\arc directory. Note that directory shoul be exist and you do not need specify name of file which you want to download, script saves file with name that specified in url (url is sensitive for register).
# version: 1.01
# type: script
# author: greg zakharov
# license: CC0
# x-poshcode-id: 4437
# x-archived: 2016-05-31T08:39:32
# x-published: 2016-09-03T11:35:00
#
#
@set @script=0 /*
  @echo off
    set @script=
    setlocal
      set "i=0"
      for %%i in (%*) do set /a "i+=1"
      if "%i%" equ "2" (
        cscript //nologo //e:jscript "%~dpnx0" %1 %2
      ) else (
        echo %~n0 v1.01 - download files from internet
        echo Copyright ^(C^) 2010-2013 greg zakharov gregzakh@gmail.com
        echo.
        echo Usage: %~n0 ^<local_path^> ^<url^>
        echo.
        echo Example:
        echo   %~n0 E:\arc http://download.sysinternals.com/files/Autoruns.zip
      )
    endlocal
  exit /b
*/

with (WScript.Arguments) {
  with (new ActiveXObject('Scripting.FileSystemObject')) {
    var file = Unnamed(1).substring(Unnamed(1).lastIndexOf('/') + 1, Unnamed(1).length);
    
    if (FolderExists(Unnamed(0))) {
      with (new ActiveXObject('MSXML2.XMLHTTP.3.0')) {
        try {
          open('GET', Unnamed(1), false);
          send();
        }
        catch (e) {}
        
        if (status == 200) {
          with (new ActiveXObject('ADODB.Stream')) {
            Open();
            Type = 1;
            Write(responseBody);
            SaveToFile(Unnamed(0) + '\\' + file);
            Close();
          }
        }
        else WScript.echo('Error: bad request.');
      }
    }
    else WScript.echo('Error: folder should be exist.');
  }
}