carloselectro Posted January 23, 2018 Posted January 23, 2018 (edited) 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 January 23, 2018 by carloselectro
rcmaehl Posted January 23, 2018 Posted January 23, 2018 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 WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF
rcmaehl Posted January 23, 2018 Posted January 23, 2018 Looks like FOSSHub doesn't allow direct download links without returning an HTML page due to bandwidth stealing 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 WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF
carloselectro Posted January 23, 2018 Author Posted January 23, 2018 Can I get around this using the WinHttp-UDFs perhaps?
rcmaehl Posted January 23, 2018 Posted January 23, 2018 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 WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF
Danp2 Posted January 23, 2018 Posted January 23, 2018 You could probably do it like this -- Use _InetGetSource to read the HTML page Parse the results to extract the actual download link Use InetGet to download the actual file Latest Webdriver UDF Release Webdriver Wiki FAQs
carloselectro Posted January 23, 2018 Author Posted January 23, 2018 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
Danp2 Posted January 23, 2018 Posted January 23, 2018 1 hour ago, carloselectro said: My goal is updating keepass automaticaly by script Not exactly what you are wanting, but have you looked into Chocolatey? Latest Webdriver UDF Release Webdriver Wiki FAQs
carloselectro Posted January 28, 2018 Author Posted January 28, 2018 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now