Download newest file from website

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Download newest file from website

Post by newuser » Tue Jul 09, 2013 9:42 am

This is the website.

http://www.gammadyne.com/

I would like to download the newest file from this website each time I check this website to a folder named C:\Tools

Example
If wol.exe exist on website but not exist on C:\Tools, then download the file.

If wol.exe exist on website and also C:\Tools, then check filesize, if filesize same, skip, if filesize not same, then delete the C:\Tools\wol.exe and download the wol.exe from website.

Its a http website not a ftp, anyone have any examples or can point me to one, so I can get started.

Thank you.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Jul 09, 2013 10:49 am

Use HTTPRequest to download file to temp folder, then do the compares/moves.

HTTPRequest>http://www.gammadyne.com/wol.exe,%TEMP_DIR%\wol.exe,GET,,

So this downloads it to your temp directory. The script can then:

-. See if file exists in c:\tools (IfFileExists)
-. If not, MoveFile from temp dir
-. If it does, use FileSize to get size of each and compare
-. And if needed, DeleteFile c:\tools\wol.exe and then MoveFile from TEMP_DIR
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Tue Jul 09, 2013 12:27 pm

This is my code based on your suggestion, Marcus.
[code]
HTTPRequest>http://www.gammadyne.com/wol.exe,%TEMP_DIR%\wol.exe,GET,,

IfNotFileExists>c:\Tools\wol.exe
MoveFile>%TEMP_DIR%\wol.exe,c:\Tools\wol.exe
Exit>0
Endif

FileSize>%TEMP_DIR%\wol.exe,MyFileSize

FileSize>c:\Tools\wol.exe,MyFileSize1


IF>MyFileSizeMyFileSize1
DeleteFile>c:\Tools\wol.exe
MoveFile>%TEMP_DIR%\wol.exe,c:\Tools\wol.exe
ELSE
DeleteFile>%TEMP_DIR%\wol.exe
Exit>0
ENDIF
[/code]

Theres two problem here,

1) The newest file is not known to me, like wol.exe might be take.exe etc(it can be anyname). How to download that newest filename?

2) Httprequest only download file then do comparison, for small file, its ok but for big file, not ok.

Any solution to the above problem 1) or 2) or both? :?:

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Jul 09, 2013 3:30 pm

1. Not sure what you mean, you need to know the file to download unless the website provides a directory listing which is highly unlikely especially for the root folder.

2. Again unless the website lets you download a directory listing there is nothing you can do about this.

Silly question, but have you asked the web master for this site?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Tue Jul 09, 2013 4:55 pm

Nope, I never ask.

I was using its freeware tools, like wol.exe etc.

If its impossible to download any file without an actual known filename.
I can accept that, I just need to browser its website once awhile.

But what about directly checking and comparing the website filenameA filesize and local existing filenameA filesize?

If filesize different, then delete local filenameA file then download website filenameA again, instead downloading website filenameA, then compare both files locally.

The reason for filesize check its because some file sizes are huge, i intend to do this checking onceawhile, so that whenever a filesize different, that means new software version is released, eg wol.exe, gpatch.exe, dels.exe etc. Those filenames never changed, what changed are filesizes only.

If filesize checking works before downloading, I can implement same method to other websites too whereby some file sizes are very huge and I have a very slow broadband. :(

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Wed Jul 10, 2013 3:02 am

You Could Use Something Like Web Recorder As Well But I Think The Issue Your Going To Run Into Is You Can't Really Check The File Size Until You Have Downloaded The File. Unless The Website Provided A FTP Or HTTP Directory Listing That You Can Check I Think You Will Have To Download Them & Then Check.

Code: Select all

// Generated by MacroScript WebRecorder 4.01
// Recorded on Wednesday, July 10, 2013, at 12:32 PM

//Move the mouse cursor out of harm's way to avoid causing mouseover events to interrupt
MouseMove>0,0
Let>delay=1

//Enable automatic downloads to My Documents dir, modify path if required
IEOnDownload>1,C:\Temp,ie_res

//Set timeout for ClickTag and FormFill to 10 seconds, increase if pages load more slowly
IESetTimeout>10,ie_res

IECreate>IE[0]

IENavigate>%IE[0]%,http://www.gammadyne.com/download.htm,ie_res

IEWaitDocumentComplete>%IE[0]%,ie_res

IEClickTag>%IE[0]%,{""},{""},{"A"},{"TEXT"},{"Download"},ie_res

Let>downloaded_filename=C:\Temp\wol.exe
Let>downloaded_filesize=77936
IEWaitFileDownload>wol.exe,ie_res
IEQuit>%IE[0]%,ie_res
FIREFIGHTER

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Wed Jul 10, 2013 9:59 am

Thanks CyberCitizen

But your code always download Centurion Setup file instead.
And also it doesnt cater for the blockdownload file internet explorer taskbar.

Anyway, after one almost sleepless night, I came out with this not so perfect simple solution below(not so perfect-> though I could use MS to do the whole thing without external tools).

Below is a simple batch file using wget tool.

wget.exe -N --directory-prefix=C:\Tools http://www.gammadyne.com/wol.exe

As a present for myself, I now got panda eyes. :(

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Fri Jul 12, 2013 5:50 pm

Can anyone tells me whats wrong with my code below

[code]
Let>WLN_ENCODING=UNICODE

IfFileExists>C:\freeware.html
DeleteFile>C:\freeware.html
Endif

IfFileExists>C:\Exist.txt
DeleteFile>C:\Exist.txt
Endif





HTTPRequest>http://www.gammadyne.com/download.htm,C ... MLResponse

Let>k=1
While>line##EOF##
ReadLn>C:\freeware.html,k,line
If>line##EOF##
Position>Free DOS Utilities,line,1,StartPos
If>StartPos0
Goto>SecondPart
EndIf
Endif
Let>k=k+1
EndWhile

Label>SecondPart

While>line##EOF##
ReadLn>C:\freeware.html,k,line
If>line##EOF##
Position>.exe">Download,line,1,StartPos
If>StartPos0
StringReplace>line,newgreeting,">Download,,newgreeting
WriteLn>C:\Exist.txt,result,newgreeting
EndIf
Endif
Let>k=k+1
EndWhile
[/code]

I intend to read the Exist.txt contents and use wget to download those filenames in it.

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Sun Jul 14, 2013 4:54 am

Ok I guess I forgot about the IGNOREERRORS=1, now I added it in.

The problem now is, the exist.txt file list all .exe files in freeware.html but I only want the Free DOS Utilities .exe list only.

[code]
Let>IGNOREERRORS=1


IfFileExists>C:\freeware.html
DeleteFile>C:\freeware.html
Endif

IfFileExists>C:\Exist.txt
DeleteFile>C:\Exist.txt
Endif





HTTPRequest>http://www.gammadyne.com/download.htm,C ... MLResponse

Let>k=1
While>line##EOF##
ReadLn>C:\freeware.html,k,line
If>line##EOF##
Position>Free DOS Utilities,line,1,StartPos
If>StartPos0
Goto>SecondPart
EndIf
Endif
Let>k=k+1
EndWhile

Label>SecondPart
Let>k=k+1
While>line##EOF##
ReadLn>C:\freeware.html,k,line
If>line##EOF##
Position>.exe">Download,line,1,StartPos
If>StartPos0
StringReplace>line,newgreeting,">Download,,newgreeting
WriteLn>C:\Exist.txt,result,newgreeting
EndIf
Endif
Let>k=k+1
EndWhile
[/code]
Any help on this problem of mine?

The reason I didnt use regex, is because after reading the get ip address example, I still cant figure out how its done. So I use the only method I understand which is Position function, then I use string function to get the names of the exe files, with this method, I'll always get all the .exe filenames I want but I only want the .exe files in Free DOS Utilities list.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sun Jul 14, 2013 1:52 pm

I've tweaked your script. I replaced while with repeat and removed a few lines.

Code: Select all

IfFileExists>C:\freeware.html
  DeleteFile>C:\freeware.html
Endif

IfFileExists>C:\Exist.txt
  DeleteFile>C:\Exist.txt
Endif





HTTPRequest>http://www.gammadyne.com/download.htm,C:\freeware.html,GET,,HTMLResponse
//Get total number of lines in freeware.html
ReadFile>C:\freeware.html,HTMLRes
Separate>%HTMLRes%,CRLF,TotalLines
//Make sure C:\freeware.html has <h2>Free DOS Utilities</h2> in it
//If not, display error
Position><h2>Free DOS Utilities</h2>,HTMLRes,1,StartPos
IF>StartPos>0
  Let>k=1
  Repeat>k
    ReadLn>C:\freeware.html,k,line
    Position><h2>Free DOS Utilities</h2>,line,1,StartPos
    If>StartPos<>0
        Goto>SecondPart
    EndIf
    Let>k=k+1
  Until>k,%TotalLines_Count%
 
  Label>SecondPart
  Let>k=k+1
  Repeat>k
    ReadLn>C:\freeware.html,k,line
    Position>.exe">Download</a></td>,line,1,StartPos
    If>StartPos<>0
      StringReplace>line,<td><a href=",,newgreeting
      StringReplace>newgreeting,">Download</a></td>,,newgreeting
      WriteLn>C:\Exist.txt,result,newgreeting
    EndIf
    Let>k=k+1
  Until>k,%TotalLines_Count%

  //Display Downloads Result
  ReadFile>C:\Exist.txt,DownloadsRes
  MDL>DownloadsRes

ELSE
  //Display Error
  MDL>There was an error

ENDIF

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Sun Jul 14, 2013 3:04 pm

Thank you, your script work perfectly. :)

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts