Windows batch download file from URL using a proxy -


i have schelude download of xls file web , save local folder every morning. make cmd file , use windows scheduler.

the file has same url, www.example.com/myfile.xls.

i've found tutorial , snipped of code my problem need use proxy server ("proxy.mycompany.com" , port "1234").

is possible cmd file or need move other solutions (vb.net, ...)?

i advise use jscript embedded in .cmd

@set @tmpvar=1 /* @echo off  echo downloading... call :download "http://download.qt.io/official_releases/jom/jom.zip" || echo failed  echo downloading using proxy... call :download "http://download.qt.io/official_releases/jom/jom_1_1_1.zip" "206.128.191.77:8008" || echo failed  goto :eof  rem  function :download rem    %1 - url rem    %2 - [proxy] rem    %3 - [file name] :download cscript /nologo /e:jscript "%~f0" %* exit /b %errorlevel%  */  function getfilename(uri) {     var re = /\/([^?/]+)(?:\?.+)?$/;     var match = re.exec(uri);     return match != null ? match[1] : "output"; }  try {      var source = wscript.arguments.item(0);     var proxy  = wscript.arguments.length > 1 ? wscript.arguments.item(1) : "";     var target = wscript.arguments.length > 2 ? wscript.arguments.item(2) : getfilename(source);      var object = wscript.createobject('msxml2.serverxmlhttp');     if (proxy.length > 0) {         object.setproxy(2/*sxh_proxy_set_proxy*/, proxy, "");     }     object.open('get', source, false);     object.send();     if (object.status != 200) {         wscript.echo('error:' + object.status);         wscript.echo(object.statustext);         wscript.quit(1);     }      var file = wscript.createobject('scripting.filesystemobject');     if (file.fileexists(target)) {         file.deletefile(target);     }      var stream = wscript.createobject('adodb.stream');     stream.open();     stream.type = 1/*adtypebinary*/;     stream.write(object.responsebody);     stream.position = 0;     stream.savetofile(target, 2/*adsavecreateoverwrite*/);     stream.close();  } catch (e) {     wscript.echo("--------------------");     wscript.echo("error " + (e.number & 0xffff) + "\r\n  " + e.description.replace(/[\r\n]*$/, "\r\n"));     (var = 0; < wscript.arguments.length; ++i) {         wscript.echo("  arg" + (i+1) + ": " + wscript.arguments(i));     }     wscript.echo("--------------------");     wscript.quit(1); } 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -