-1

Is it possible to download a file in intervals from a specified URL to a specified location in an easy way?

I created VBScript:

Set args = WScript.Arguments
path = ""
datePath = ""
Url = ""

dim filesys
Set filesys = CreateObject("Scripting.FileSystemObject")

Do
    If filesys.FileExists(path) Then 
        filesys.DeleteFile path
    End If

    dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
    dim bStrm: Set bStrm = createobject("Adodb.Stream")
    xHttp.Open "GET", Url, False
    xHttp.Send 
    with bStrm
      .type = 1 '//binary
       .open
       .write xHttp.responseBody
       .savetofile path, 2 '//overwrite
    end with


    If(xHttp.Status = 200) Then
        If filesys.FileExists(datePath) Then 
            filesys.DeleteFile datePath
        End If
        Set dateFile = filesys.CreateTextFile(datePath)
        dateFile.WriteLine(FormatDateTime(Now))
        dateFile.close()
    End If
    WScript.Sleep 600000
Loop

But it doesn't work as it returns following prompt:

This page is accessing information that is not under its control. This poses a security risk. Do you want to continue?

I tried to disable notification by changing internet options but it also doesn't work for me. I need the script to work even when I am absence in my job thus I need to improve/change this to be maintenance-free. It also needs to work on Windows OS.

I also tried to use powershell > wget but then authentication problem occures as file i need to get is in secured business's infranet and need to use my login credentials I tried to provide them in URL or as wget arguments --user/-password - It doesn't work because login procedure requires redirections. VBScript uses my current session thus infranet security system allows it to get in.

Is anyone able to help with my problem?

Shiffer
  • 1
  • 3
  • I’d use wget + windows task scheduler for something like that … https://stackoverflow.com/questions/14923562/running-a-php-script-using-wget-and-windows-scheduler – 04FS Dec 02 '19 at 08:17
  • Hi, I found this question before, and part of this code exits in my script. My problem is, that this way returns prompt which stops my loop. So it doesn't. – Shiffer Dec 02 '19 at 10:45

1 Answers1

0

Add a task in Task Scheduler with whatever schedule you like, and in the action, add this:

start a program: Powershell

argument: wget URL -OutFile FILEADDRESS

Matthew
  • 1,412
  • 2
  • 20
  • 35
FarhadGh
  • 134
  • 11
  • Can I ask why a down vote? this answer just works! – FarhadGh Dec 02 '19 at 08:49
  • Hi, Thanks for your reply, i will try it. When it comes to down vote It wasn't me - I gave you up vote just right now. Anyway i have no reputation for that my vote will be visible. – Shiffer Dec 02 '19 at 08:54
  • Is it possible to also update file containing date when wget finishes download? – Shiffer Dec 02 '19 at 09:01
  • yes, use this argument instead: `wget URL -OutFile FILEADDRESS; if($?) {echo $(Get-Date) > DATEFILEADDRESS}` – FarhadGh Dec 02 '19 at 09:10
  • Thanks a lot. I will try. – Shiffer Dec 02 '19 at 10:41
  • Unfortunately this way doesn't work as there are security restrictions in an infranet which needs authorization. I tried to use `https://login:pass@host` in URL or `--user user --password pass` preffix but it still returns _Username/Password Authentication Failed._ Waiting for more ideas. – Shiffer Dec 02 '19 at 11:26
  • you should have mentioned that there is authentication. whether it is intranet proxy or basic authentication or jwt, you can still use wget. check `man wget` for detail about different authentications. If its basic or jwt, you should add a header with user/pass or token. – FarhadGh Dec 02 '19 at 12:00