Tjalve Posted October 28, 2013 Posted October 28, 2013 Hello everyone. Im having an issue with the InetGet function and i was hoping someone could help me provide som assiatnce. Im writing a script that monitor serveral servers and send information about performance characterics using a webbservice, to a server. I then get a dashboard of thye health of all my serverers. To this. Ive written a simpel update program. The idee is that the program should check online for a new version and if found, dowload and install it. In testing it all works, but in practise ive run into server issues. One was that the updater program (a separte script from the main script) was crashing when trying to unzip the downloaded zip file (witch contains the new version of thne scrips and configuration for the script). This happend at ablur 60% of all the servers. On close inspection it seems that the InetGet function doesnt download the entire file. It just downloads about 140KB of it. Therefore the unziping of the file crashes the script. To not crash the script, i added a check to see the size of the file befor the DL and after the DL. That works of couse, but it doesnt solve the problem. I guess it has to do with firewalls and antovirus software, softaware or somthing like that. The problem is that theese servers are on infrastracture that is out of my control. Downloading the file manually trough internet explorer seems to work though. Any help would be appritiated. Here is a part of my code. $dlsize = InetGetSize ($dl4,1) FileWriteLine(@ScriptDir & "\verbose.log", @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " - Updater - Downloading file: " & $dl4) FileWriteLine(@ScriptDir & "\verbose.log", @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " - Updater - File is: " & $dlsize & " bytes.") InetGet($dl4,@TempDir & "\system.zip",1) sleep(2000) $retry = 10 while 1 if FileExists(@TempDir & "\system.zip") then if $dlsize = FileGetSize(@TempDir & "\system.zip") then FileWriteLine(@ScriptDir & "\verbose.log", @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " - Updater - Download OK") ExitLoop EndIf Else FileWrite(@TempDir & "\system.zip",InetRead($dl4,1)) EndIf sleep(1000) if $retry = 0 then FileWriteLine(@ScriptDir & "\verbose.log", @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " - Updater - Download Faild") if $silent = 0 then MsgBox(0,"ERROR","Could not download file. Check Antivirus and firewalls.") Exit EndIf $retry = $retry - 1 WEnd
Jury Posted October 28, 2013 Posted October 28, 2013 Have you read the Remarks part of the help file entry for InetGet ?
BrewManNH Posted October 28, 2013 Posted October 28, 2013 I believe you might be downloading a binary file in ASCII mode, try something like this instead see if it makes any difference. InetGet($dl4,@TempDir & "\system.zip",9) ; Binary mode If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Tjalve Posted October 28, 2013 Author Posted October 28, 2013 I believe you might be downloading a binary file in ASCII mode, try something like this instead see if it makes any difference. InetGet($dl4,@TempDir & "\system.zip",9) ; Binary mode Thanx. Ill give it a shot. The strange thing is that it seems to be working on some servers (including my own machine). Im also downloading a small text file (with the version information in it) and that one always download. But that might be becuase its so small perhaps. But i will try .
Tjalve Posted October 28, 2013 Author Posted October 28, 2013 I have now tested. I also did a filewritleline to see how mutch of the file has been downloaded every secound. I get 166912 bytes everytime. Binary dodnt help. And it seems if the file is smaller then that, it works. But i cannot be 100% sure. Any more idees?
BrewManNH Posted October 28, 2013 Posted October 28, 2013 One thing I might suggest trying is to use FileOpen in binary and write mode before using this line: FileWrite(@TempDir & "\system.zip",InetRead($dl4,1)) Also, use binary mode on the InetRead line as well. FileWrite may also be failing to write the complete file correctly if it's binary data and you're trying to write it without opening the file in binary mode. Just a thought I had. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Tjalve Posted October 29, 2013 Author Posted October 29, 2013 One thing I might suggest trying is to use FileOpen in binary and write mode before using this line: FileWrite(@TempDir & "\system.zip",InetRead($dl4,1)) Also, use binary mode on the InetRead line as well. FileWrite may also be failing to write the complete file correctly if it's binary data and you're trying to write it without opening the file in binary mode. Just a thought I had. you mean like this? $filmeck = FileOpen(@TempDir & "\test.zip",18) FileWrite($filmeck,InetRead($dl4,9)) FileClose($filmeck) I tried that, but i just ended up with an empty zip file at 0 bytes.
Tjalve Posted October 29, 2013 Author Posted October 29, 2013 (edited) Alright. Ive done som more digging. I uploaded a new file and everything worked just as it should, for a while. Now i get the same results again, but this time it stuck at 800KBs. If feels like there is something blocking the DL. I dont know. Some kind of antivirus or somthing? Anyone have any idees? If i just enter the URL in IE on the server. Then i can DL and save the entire file without issues. Edited October 29, 2013 by Tjalve
IUtilizeScripts Posted January 2, 2014 Posted January 2, 2014 Tjalve, I have a similar issue: Every time I utilize InetGet for a ZIP file, the saved file is 8kb (even when downloading from my local machine). I can manually enter the URL in IE and the file downloads properly. I have no problems downloading other filetypes such as PDF and TXT using InetGet. Did you find a solution to this?
exolon Posted January 3, 2014 Posted January 3, 2014 A couple of questions which may help track down the error. Why do you call Sleep() in your script, if you're downloading synchronously (i.e. blocking until the download completes)? You haven't specified 1 for the optional "background" parameter, so presumably it is blocking as it should. Why don't you assign the return value of the InetGet() call to a variable and check that it matches the expected size (and/or actual size)? If the return value was zero, then have you checked the @error variable after the InetGet() call?
AutID Posted January 3, 2014 Posted January 3, 2014 (edited) InetGet works fine for me for zip files. However try this one. Global $sPath = @ScriptDir & "\test.zip" $sUrl = "http://download.thinkbroadband.com/20MB.zip" FileDownload($sUrl, $sPath) Func FileDownload($url, $SavePath) Local $xml, $Stream $xml = ObjCreate("Microsoft.XMLHTTP") $Stream = ObjCreate("Adodb.Stream") $xml.Open("GET", $url, 0) $xml.Send $Stream.Type = 1 $Stream.Open $Stream.write($xml.ResponseBody) $Stream.SaveToFile($SavePath) $Stream.Close EndFunc Edited January 3, 2014 by AutID https://iblockify.wordpress.com/
IUtilizeScripts Posted January 3, 2014 Posted January 3, 2014 InetGet works fine for me for zip files. However try this one. Global $sPath = @ScriptDir & "\test.zip" $sUrl = "http://download.thinkbroadband.com/20MB.zip" FileDownload($sUrl, $sPath) Func FileDownload($url, $SavePath) Local $xml, $Stream $xml = ObjCreate("Microsoft.XMLHTTP") $Stream = ObjCreate("Adodb.Stream") $xml.Open("GET", $url, 0) $xml.Send $Stream.Type = 1 $Stream.Open $Stream.write($xml.ResponseBody) $Stream.SaveToFile($SavePath) $Stream.Close EndFunc Thanks AudID, The aforementioned file downloads with no issues. The problem I'm experiencing must be with a particular website / download protocol.
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