Jump to content

Cannot download zip files with InetGet


Recommended Posts

Hi,

I cannot get InetGet to download a zip file from fosshub.com with this code. The thing that puzzles me is the fact that it works with many url links without any problem.

If I paste the URL link in my browser, it's downloading the file correctly.

What am I doing wrong? If I open the downloaded zip file with a text editor it's actually the html page that is downloaded instead of the actual zip file.

 

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <InetConstants.au3>

; Download a file in the background.
; Wait for the download to complete.

Example()

Func Example()
    ; Save the downloaded file to the temporary folder.
    Local $sFilePath = "C:\My downloaded file.zip"

    ; Download the file by waiting for it to complete. The option of 'get the file from the local cache' has been selected.
    Local $iBytesSize = InetGet("https://www.fosshub.com/KeePass.html/KeePass-2.38.zip", $sFilePath, $INET_FORCERELOAD)

    ; Retrieve the filesize.
    Local $iFileSize = FileGetSize($sFilePath)

    ; Display details about the total number of bytes read and the filesize.
    MsgBox($MB_SYSTEMMODAL, "", "The total download size: " & $iBytesSize & @CRLF & _
            "The total filesize: " & $iFileSize)

     
EndFunc   ;==>Example

 

 

Edited by carloselectro
Link to comment
Share on other sites

Seems like for some reason that url is returning an HTML page instead of just the file...

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

You can attempt to but it'll probably be way more of a hassle compared to finding a site that supports direct downloads.

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

It's pretty much what I do with another function using winhttp and regex, but the actual download link is not working with inetget afterward anyway.

My goal is updating keepass automaticaly by script. The problem is that I cannot find a direct link without the version number in the name, so a regex is the only way to go.

Func Get_download_link($url_address, $regexpattern)


    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $agent = 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36'
    $url = $url_address
    $oHTTP.Open("GET", $url, False)
    $oHTTP.setRequestHeader("User-Agent", $agent)
    $oHTTP.Option(4) = 13056
    $oHTTP.Send()
    $src = ($oHTTP.ResponseText)
    $patern = $regexpattern
    $link = StringRegExp($src, $patern, 1)
    If @error Then
        ConsoleWrite("ERROR No match found in pattern for URL"  & $url_address)
        _DebugOut("ERROR No match found in pattern for URL " & $url_address)
    Else

        Return $url & $link[0]

        ;ConsoleWrite($url & $link[0])

    EndIf

EndFunc   ;==>Get_download_link

 

 

Link to comment
Share on other sites

I ended up using ie.au3 to get the secure url and doing a regex after getting the source from the page.

Here's my working code:

#include <Inet.au3>
#include <ie.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <InetConstants.au3>


Example()

Func Example()

    $oIE = _IECreate("https://www.fosshub.com/KeePass.html", 0, 0)
    _IELoadWait($oIE)
    Local $url_direct_link_page = _IEBodyReadHTML($oIE)
    _IEQuit($oIE)
    $array_url_download = StringRegExp($url_direct_link_page, '(?s).*fdslwdx="(.*?zip).*(?<=Portable - Professional)', 1)
    ; Save the downloaded file to the temporary folder.
    Local $sFilePath = "C:\My downloaded file.zip"

    ; Download the file by waiting for it to complete. The option of 'get the file from the local cache' has been selected.
    Local $iBytesSize = InetGet($array_url_download[0], $sFilePath, $INET_FORCERELOAD)

    ; Retrieve the filesize.
    Local $iFileSize = FileGetSize($sFilePath)

    ; Display details about the total number of bytes read and the filesize.
    MsgBox($MB_SYSTEMMODAL, "", "The total download size: " & $iBytesSize & @CRLF & _
            "The total filesize: " & $iFileSize)

     
EndFunc   ;==>Example

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...