script that will download .zip file from URL (zip file names date is different everyday)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
danceman96
Posts: 7
Joined: 30 Nov 2021, 09:47

script that will download .zip file from URL (zip file names date is different everyday)

Post by danceman96 » 12 May 2022, 03:23

Hi,
I am looking for a way to automatically download a zip file that is located on a small server, accessible through a web browser (through IP).
It is about downloading a backup zip file, which always has the current date added in its name - hence the file name and the exact URL link is different every day.

link to file is:
http://10.200.182.AB/CDE/FGHI/zrzut20220512.zip

tommorow file name will be: zrzut20220513.zip , so the link will be:
http://10.200.182.AB/CDE/FGHI/zrzut20220513.zip

etc... :D

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: script that will download .zip file from URL (zip file name is diffrent everyday)

Post by BoBo » 12 May 2022, 04:41

Code: Select all

#Persistent

urlPath 	:= "http://10.200.182.ab/CDE/FGHI/"	; corrected error mentioned below. Replaced trailing “ with " character.
fName		:= "zrzut"
localPath	:= A_ScriptDir "\" 
fExt		:= ".zip"

SetTimer, getUpdate,% 5*60*1000 ; 5min for testing (1*24*60*60*1000 ; get updated file every 24hrs)
Return

getUpdate:
	FormatTime, date,, yyyyMMdd
	MsgBox % urlPath . fName . date . fExt . "`n`n" . localPath . fName . fExt		; just to check out if the paths are fine
	UrlDownloadToFile,% urlPath . fName . date . fExt,% localPath . fName . date . fExt
	Return
HTH :)

PS. btw, this example script from AHK's Help would provide a more "fail save" download option: https://www.autohotkey.com/docs/commands/URLDownloadToFile.htm#XHR
JFTR

danceman96
Posts: 7
Joined: 30 Nov 2021, 09:47

Re: script that will download .zip file from URL (zip file name is diffrent everyday)

Post by danceman96 » 13 May 2022, 04:16

@BoBo
Hello,
thank you!

Thank you very much.
Unfortunately, when I try to run Script, I get an error:
Image

script is:

Code: Select all

#Persistent

urlPath 	:= "http://10.200.182.94/rcp/zrzut/“
fName		:= "zrzut"
localPath	:= A_ScriptDir "\" 
fExt		:= ".zip"

SetTimer, getUpdate,% 5*60*1000 ; 5min for testing (1*24*60*60*1000 ; get updated file every 24hrs)
Return

getUpdate:
	FormatTime, date,, yyyyMMdd
	MsgBox % urlPath . fName . date . fExt . "`n`n" . localPath . fName . fExt		; just to check out if the paths are fine
	UrlDownloadToFile,% urlPath . fName . date . fExt,% localPath . fName . date . fExt
	Return

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: script that will download .zip file from URL (zip file names date is different everyday)

Post by BoBo » 13 May 2022, 04:29

As the error message correctly pointed out... it's a typo (if you have bad eyesight you need probably your glasses bc it's obviously not that obvious)

Code: Select all

urlPath 	:= "http://10.200.182.ab/CDE/FGHI/“
urlPath 	:= "http://10.200.182.ab/CDE/FGHI/"
Spot the difference ;)
Hint: enclosing strings in expressions is done using the " character. Now check out the error message again...

danceman96
Posts: 7
Joined: 30 Nov 2021, 09:47

Re: script that will download .zip file from URL (zip file names date is different everyday)

Post by danceman96 » 13 May 2022, 06:59

BoBo wrote:
13 May 2022, 04:29
As the error message correctly pointed out... it's a typo (if you have bad eyesight you need probably your glasses bc it's obviously not that obvious)

Code: Select all

urlPath 	:= "http://10.200.182.ab/CDE/FGHI/“
urlPath 	:= "http://10.200.182.ab/CDE/FGHI/"
Spot the difference ;)
Hint: enclosing strings in expressions is done using the " character. Now check out the error message again...
thank mate, now it's working!

danceman96
Posts: 7
Joined: 30 Nov 2021, 09:47

Re: script that will download .zip file from URL (zip file names date is different everyday)

Post by danceman96 » 16 May 2022, 03:38

BoBo wrote:
13 May 2022, 04:29
As the error message correctly pointed out... it's a typo (if you have bad eyesight you need probably your glasses bc it's obviously not that obvious)

Code: Select all

urlPath 	:= "http://10.200.182.ab/CDE/FGHI/“
urlPath 	:= "http://10.200.182.ab/CDE/FGHI/"
Spot the difference ;)
Hint: enclosing strings in expressions is done using the " character. Now check out the error message again...

@BoBo
Before each file is prepared, a message like the one below is displayed:
image.png
image.png (11.87 KiB) Viewed 507 times

Without clicking "OK" the file does not download itself. Can I make it so that I do not have to confirm with "OK" and to automate this completely?

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: script that will download .zip file from URL (zip file names date is different everyday)

Post by BoBo » 16 May 2022, 05:02

Check out AHK's Help about how to comment out code. So, do just that with a ; MsgBox ;)

danceman96
Posts: 7
Joined: 30 Nov 2021, 09:47

Re: script that will download .zip file from URL (zip file names date is different everyday)

Post by danceman96 » 17 May 2022, 08:49

however, I would like to ask for your concrete help, as I am green in this subject :)

Post Reply

Return to “Ask for Help (v1)”