vtphilk Posted April 5, 2012 Share Posted April 5, 2012 I'm strungling to get a file downloader to work. InetGet keeps hanging and I'm not sure why becaues I thought I had this working sort of several months ago, so I thought. Basically, since the UVNC installer is big I was trying to build a AutoIT installer script that would check if the OS is 32bit or 64bit then go do a http download to a folder in the %TEMP% on windows. After that is done then run it and install the correct version of VNC. I also wanted to give a progress bar while the installer is downloading. I also have another app that is around 50 megs I have to download and install so the UltraVNC is just phase 1. Now I have no Idea what is going on but figured I would post the code and see if anyone has any ideas. Originally I was using the func "DownloadFile" then that stopped working. So I thought it was because the Filesize was not getting populated because the size would always say 0 out of 0 bytes. So I found the function in the forums "_InetGetSizeEx". That seems to get the site of the file just fine but did not fix my download. I then got the func _InetGetProgress from the forums and still no luck. It still will not download the .exe with progress bar. Checking the windos TEMP folder and nothing in it. Please help!!! any pointers would be much appreciated. I wonder if there is something wrong with my autoIT install. Cause I swear this worked a few months ago!!! Thanks, -vtphilk expandcollapse popup#RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ConsoleWrite("SciTE or Command-line Console Output"&@CRLF) $HTTPFilePath = "http://gtsvm.genband.com/setup/" $tempfiledir = @TempDir & "\TECHOPS\" $return = DirCreate($tempfiledir) If $return = 0 Then MsgBox(0, "File install error 1", "Unable to create temporary folder..exiting") Exit EndIf If @OSArch = "X64" Then $osbitname = " 64 Bit" $FileNameToDownload = "UltraVNC_1.0.9.6.2-64bit.exe" $FileURL = $HTTPFilePath & $FileNameToDownload ;DownloadFile($FileURL,$FileNameToDownload) _InetGetProgress($FileURL, $tempfiledir) Sleep(1000) RunWait($tempfiledir & $FileNameToDownload & " x -o""" & $tempfiledir & """ -y") $InstallerToRun = $tempfiledir & "UltraVNC_1.0.9.6.2_x64_Setup.exe" Else $osbitname = " 32 Bit" $FileNameToDownload = "UltraVNC_1.0.9.6.2-32bit.exe" $FileURL = $HTTPFilePath & $FileNameToDownload ; DownloadFile($FileURL,$FileNameToDownload) _InetGetProgress($FileURL, $tempfiledir) Sleep(1000) RunWait($tempfiledir & $FileNameToDownload & " x -o""" & $tempfiledir & """ -y") $InstallerToRun = $tempfiledir & "UltraVNC_1.0.9.6.2_Setup.exe" EndIf If FileExists($InstallerToRun) Then Sleep(1000) RunWait(@ComSpec & " /c start /w " & $InstallerToRun & " /silent /loadinf=" & $tempfiledir & "UltravncInstall.inf ") If FileExists("C:\Program Files\UltraVNC\vncviewer.exe") Then MsgBox(4096,"VNC Installer","UltraVNC for your" & $osbitname &" OS has been installed.",10) If FileExists("C:\Program Files\UltraVNC\vncviewer.exe") And $CmdLineRaw Then RunWait("C:\Program Files\UltraVNC\vncviewer.exe " & $CmdLineRaw) EndIf Else MsgBox(4096,"VNC Installer","The install may have failed..please try again if VNC does not work.",10) EndIf Else MsgBox(4096,"ERROR","An error occured, could not find install EXE..Exiting.") Exit EndIf FileDelete($tempfiledir) DirRemove($tempfiledir) Func DownloadFile($FileURL2,$FileNameToDownload2) MsgBox(4096,"VNC Installer1",$FileURL2 & "|" & $FileNameToDownload2) $tempfiledir = @TempDir & "\TECHOPS\" $FileSaveLocation = $tempfiledir & $FileNameToDownload2 $FileSize = _InetGetSizeEx($FileURL2) MsgBox(4096,"VNC Installer", $tempfiledir & "|" & $FileSize) $Download = InetGet($FileURL2,$FileSaveLocation,1,1) ProgressOn("","") Do $Percentage = InetGetInfo($Download,0) * 100 / $FileSize ProgressSet($Percentage,"Downloaded " & InetGetInfo($Download,0) & " of " & $FileSize & " bytes","Downloading " & $FileNameToDownload2) Sleep(250) Until InetGetInfo($Download,2) ProgressOff() InetGet("") EndFunc Func _InetGetSizeEx($sURL) TCPStartup() Local $sHost = StringRegExpReplace($sURL, ".*://(.*?)/.*", "\1") Local $sPage = StringRegExpReplace($sURL, ".*://.*?(/.*)", "\1") Local $sName_To_IP = TCPNameToIP($sHost) Local $iSocket = TCPConnect($sName_To_IP, 80) If $iSocket = -1 Then TCPShutdown() Return SetError(1, 0, "") EndIf Local $sCommand = "HEAD " & $sPage & " HTTP/1.1" & @CRLF $sCommand &= "Host: " & $sHost & @CRLF $sCommand &= "User-Agent: AutoIt/" & @AutoItVersion & " (Windows; U; Windows NT 5.1; en-US; rv:1.8.1)" & @CRLF $sCommand &= "Referer: " & $sHost & @CRLF $sCommand &= "Connection: close" & @CRLF & @CRLF Local $BytesSent = TCPSend($iSocket, $sCommand) If $BytesSent = 0 Then TCPShutdown() Return SetError(2, @error, 0) EndIf Local $sRecv = "", $sCurrentRecv While 1 $sCurrentRecv = TCPRecv($iSocket, 16) If @error <> 0 Then ExitLoop If $sCurrentRecv <> "" Then $sRecv &= $sCurrentRecv WEnd TCPCloseSocket($iSocket) TCPShutdown() $sRecv = StringRegExpReplace($sRecv, "(?s).*Content-Length: (.*?)[\r\n].*", "\1") If @extended = 0 Then Return SetError(2, 0, "") Return $sRecv EndFunc ;==>_InetGetSizeEx ; Requirement(s).: v3.3.2.0 or higher ; Return values .: Success - Downloaded filename. ; Failure - Returns downloaded filename & sets @error = 1 ; Author ........: guinness ; Example........; Yes ;===================================================================================================================== Func _InetGetProgress($sURL, $sDirectory = @ScriptDir, $sFilePath = -1) MsgBox(4096,"VNC Installer1", $sURL & "|" & $sDirectory & ":" & $sFilePath) Local $hDownload, $iBytesRead = 0, $iFileSize, $iPercentage, $iSpeed = 0, $iTimer = 0, $sProgressText, $sSpeed If $sFilePath = -1 Then $sFilePath = StringRegExpReplace($sURL, "^.*/", "") If @error Then Return SetError(1, 0, $sFilePath) EndIf EndIf $sDirectory = StringRegExpReplace($sDirectory, "[\\/]+\z", "") & "\" & $sFilePath $iFileSize = InetGetSize($sURL, 1) $hDownload = InetGet($sURL, $sDirectory, 0, 1) If @error Then Return SetError(1, 0, $sFilePath) EndIf ProgressOn("", "") $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s" $iTimer = TimerInit() While InetGetInfo($hDownload, 2) = 0 $iBytesRead = InetGetInfo($hDownload, 0) $iPercentage = $iBytesRead * 100 / $iFileSize $sProgressText = "Downloading " & _ByteSuffix($iBytesRead, 0) & " Of " & _ByteSuffix($iFileSize, 0) & @LF & $sSpeed ProgressSet(Round($iPercentage, 0), $sProgressText, "Downloading: " & $sFilePath) If TimerDiff($iTimer) > 1000 Then $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s" $iSpeed = $iBytesRead $iTimer = TimerInit() EndIf Sleep(100) WEnd InetClose($hDownload) ProgressOff() Return $sFilePath EndFunc ;==>_InetGetProgress ; #INTERNAL_USE_ONLY#============================================================================================================ Func _ByteSuffix($iBytes, $iRound = 2) Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"] While $iBytes > 1023 $A += 1 $iBytes /= 1024 WEnd Return Round($iBytes, $iRound) & $aArray[$A] EndFunc ;==>_ByteSuffix Link to comment Share on other sites More sharing options...
vtphilk Posted April 5, 2012 Author Share Posted April 5, 2012 (edited) PS..I even tried the demo in the help InetGetInfo; #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Local $hDownload = InetGet("http://www.autoitscript.com/autoit3/files/beta/update.dat", @TempDir & "update.dat", 1, 1) Do Sleep(250) Until InetGetInfo($hDownload, 2) ; Check if the download is complete. Local $aData = InetGetInfo($hDownload) ; Get all information. InetClose($hDownload) ; Close the handle to release resources. MsgBox(0, "", "Bytes read: " & $aData[0] & @CRLF & _ "Size: " & $aData[1] & @CRLF & _ "Complete?: " & $aData[2] & @CRLF & _ "Successful?: " & $aData[3] & @CRLF & _ "@error: " & $aData[4] & @CRLF & _ "@extended: " & $aData[5] & @CRLF) and no joy. I get errors '13' and successfull false. Edited April 5, 2012 by vtphilk Link to comment Share on other sites More sharing options...
BrewManNH Posted April 5, 2012 Share Posted April 5, 2012 What happens if you remove or comment out the line - "#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker"? 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 Link to comment Share on other sites More sharing options...
vtphilk Posted April 5, 2012 Author Share Posted April 5, 2012 the SCITE editor keeps adding that in when I do a compile.. If I don't compile and just do a run of the example download from www.autoitscript.com 'update.dat' file it does not work there either. The results of the demo is: Bytes read: 0 Size: 0 Complete?: True Successful?: False @error: 13 @extended: 12152 Link to comment Share on other sites More sharing options...
Developers Jos Posted April 5, 2012 Developers Share Posted April 5, 2012 the SCITE editor keeps adding that in when I do a compile..No SciTE doesn't add it, but maybe AutoIt3Wrapper does that. What version are you running and I guess you are doing Ctrl+F7, which shows the GUI before the compile?I know I fixed an issue for this in the latest AutoIt3Wrapper available in the Beta directory. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
vtphilk Posted April 6, 2012 Author Share Posted April 6, 2012 (edited) Yes..I would click Tools -> Compile to check it..then build or GO. I guess i didn't really need to do the compile and the compile was adding it. When I do compile it does popup the gui and it adds that info. However, with or without the Region stuff the InetGet still is not working. At this point I'm just trying to get the demo to work and it will not. Local $hDownload = InetGet("http://www.autoitscript.com/autoit3/files/beta/update.dat", @TempDir & "update.dat", 1, 1) Do Sleep(250) Until InetGetInfo($hDownload, 2) ; Check if the download is complete. Local $aData = InetGetInfo($hDownload) ; Get all information. InetClose($hDownload) ; Close the handle to release resources. MsgBox(0, "", "Bytes read: " & $aData[0] & @CRLF & _ "Size: " & $aData[1] & @CRLF & _ "Complete?: " & $aData[2] & @CRLF & _ "Successful?: " & $aData[3] & @CRLF & _ "@error: " & $aData[4] & @CRLF & _ "@extended: " & $aData[5] & @CRLF) PS>> I have tried with both the beta run version 3.3.9.2 and the production 3.3.8.1 Both return the above demo with the following InetGetInfo fields: 0 0 True False 13 12002 Edited April 6, 2012 by vtphilk Link to comment Share on other sites More sharing options...
vtphilk Posted April 12, 2012 Author Share Posted April 12, 2012 Bump..has anyone been able to get the example in the documentation to actually work? I just want to know if I'm crazy or if this is truely broke.. Link to comment Share on other sites More sharing options...
vtphilk Posted July 6, 2012 Author Share Posted July 6, 2012 Still cannot get this to work . Has anyone "recently" used the InetGet functions to create a auto downloader. My problem is I have a 90 meg installer for vmware vsphere that I need users all around the world to install. I'm trying to automate the download/install so that the installer is only a few KB (AutoIT part) and then have autoIT download the installer and launch the install once complete. THis worked for a little while then all of a sudden stopped working! Link to comment Share on other sites More sharing options...
Mechaflash Posted July 6, 2012 Share Posted July 6, 2012 (edited) The only thing I can think of... create another script that tracks the file size of the package and that ticks every second for the size of the downloading tmp file package. Run it before you start InetGet. Never tried it... wouldn't know how to find out what the tmp download file might be named... not even sure how to check the file size of the package in question without doing it manually XD. Just some possible logic-without-knowledge. Edited July 6, 2012 by mechaflash213 Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
Mechaflash Posted July 6, 2012 Share Posted July 6, 2012 Okay... full working example with downloading foxit reader to your desktop. expandcollapse popup#include <Array.au3> Global $hInetGet $url = "http://cdn04.foxitsoftware.com/pub/foxit/reader/desktop/win/5.x/5.3/enu/FoxitReader531.0606_enu_Setup.exe" $sFileSizeBytes = InetGetSize($url, 1) $sFileSize = $sFileSizeBytes / 1048576 $asSplit = StringSplit($sFileSize, ".") If $asSplit[0] > 1 Then $sFileSize = $asSplit[1] & "." & StringLeft($asSplit[2], 1) Else $sFileSize = $asSplit[1] EndIf Local $sFileName = @DesktopDir & "FoxitReader5.31_Setup.exe" $hInetGet = InetGet($url, $sFileName, 1, 1) _DownloadProgress($sFileName, $sFileSize, $sFileSizeBytes) Exit Func _DownloadProgress(Const $sFileName, Const $sFileSize, Const $sFileSizeBytes) Local $sDlFileSize = 0 ProgressOn("Download Progress", "Downloading File", "", Default, 200, 16) While Not FileExists($sFileName) Sleep(100) WEnd Do $sDlFileSizeBytes = InetGetInfo($hInetGet, 0) $sDlFileSize = $sDlFileSizeBytes / 1048576 $asSplit = StringSplit($sDlFileSize, ".") If $asSplit[0] > 1 Then $sDlFileSize = $asSplit[1] & "." & StringLeft($asSplit[2], 1) Else $sDlFileSize = $asSplit[1] EndIf $sComplete = Round($sDlFileSizeBytes / $sFileSizeBytes * 100) ProgressSet($sComplete, $sComplete & "% Complete...", "Downloading " & $sDlFileSize & " of " & $sFileSize) Sleep(500) Until InetGetInfo($hInetGet, 3) ProgressOff() msgbox(64, "Download Progress", "Download Complete!") EndFunc Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
GMK Posted July 6, 2012 Share Posted July 6, 2012 I've tried playing with it, but I'm not able to download the file either, though I'm guessing it's because your site is an Intranet site, or some other similar reason. Now if you're having problems using the demo, then I wonder if there's something happening with a firewall or Windows security. On what version of Windows are you testing this? Here's what I've done (simplified a bit) that you can at least try:expandcollapse popup#RequireAdmin #region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** ConsoleWrite("SciTE or Command-line Console Output" & @CRLF) $sHTTPFilePath = "http://gtsvm.genband.com/setup/" $sTempFileDir = @TempDir & "TECHOPS" $iReturn = DirCreate($sTempFileDir) If $iReturn = 0 Then MsgBox(0, "File install error 1", "Unable to create temporary folder..exiting") Exit EndIf If @OSArch = "X64" Then $iBit = 64 Else $iBit = 32 EndIf $sOSBitName = " " & $iBit & " Bit" $sFileNameToDownload = "UltraVNC_1.0.9.6.2-" & $iBit & "bit.exe" $sFileURL = $sHTTPFilePath & $sFileNameToDownload _InetGetProgress($sFileURL, $sTempFileDir, -1) Sleep(1000) RunWait($sTempFileDir & $sFileNameToDownload & ' x -o "' & $sTempFileDir & '" -y') $sInstallerToRun = $sTempFileDir & $sFileNameToDownload If FileExists($sInstallerToRun) Then Sleep(1000) RunWait(@ComSpec & " /c start /w " & $sInstallerToRun & " /silent /loadinf=" & $sTempFileDir & "UltravncInstall.inf ") If FileExists("C:Program FilesUltraVNCvncviewer.exe") Then MsgBox(4096, "VNC Installer", "UltraVNC for your" & $sOSBitName & " OS has been installed.", 10) If FileExists("C:Program FilesUltraVNCvncviewer.exe") And $CmdLineRaw Then RunWait("C:Program FilesUltraVNCvncviewer.exe " & $CmdLineRaw) EndIf Else MsgBox(4096, "VNC Installer", "The install may have failed..please try again if VNC does not work.", 10) EndIf Else MsgBox(4096, "ERROR", "An error occured, could not find install EXE..Exiting.") Exit EndIf FileDelete($sTempFileDir) DirRemove($sTempFileDir) Func _InetGetProgress($sURL, $sDirectory = @ScriptDir, $sFilePath = -1) MsgBox(4096, "VNC Installer1", $sURL & "|" & $sDirectory & ":" & $sFilePath) Local $hDownload, $iBytesRead = 0, $iFileSize, $iPercentage, $iSpeed = 0, $iTimer = 0, $sProgressText, $sSpeed If $sFilePath = -1 Then $sFilePath = StringRegExpReplace($sURL, "^.*/", "") If @error Then Return SetError(1, 0, $sFilePath) EndIf EndIf $sDirectory = StringRegExpReplace($sDirectory, "[/]+z", "") & "" & $sFilePath $iFileSize = InetGetSize($sURL, 1) ConsoleWrite($sURL & " File Size: " & $iFileSize & @CRLF) $hDownload = InetGet($sURL, $sDirectory, 0, 1) If @error Then ConsoleWrite("InetGet Error: " & @error & @CRLF) Return SetError(1, 0, $sFilePath) EndIf ProgressOn("", "") $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s" $iTimer = TimerInit() While InetGetInfo($hDownload, 2) = 0 $iBytesRead = InetGetInfo($hDownload, 0) $iPercentage = $iBytesRead * 100 / $iFileSize $sProgressText = "Downloading " & _ByteSuffix($iBytesRead, 0) & " Of " & _ByteSuffix($iFileSize, 0) & @LF & $sSpeed ProgressSet(Round($iPercentage, 0), $sProgressText, "Downloading: " & $sFilePath) If TimerDiff($iTimer) > 1000 Then $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s" $iSpeed = $iBytesRead $iTimer = TimerInit() EndIf Sleep(100) WEnd InetClose($hDownload) ProgressOff() Return $sFilePath EndFunc ;==>_InetGetProgress ; #INTERNAL_USE_ONLY#============================================================================================================ Func _ByteSuffix($iBytes, $iRound = 2) Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"] While $iBytes > 1023 $A += 1 $iBytes /= 1024 WEnd Return Round($iBytes, $iRound) & $aArray[$A] EndFunc ;==>_ByteSuffix Link to comment Share on other sites More sharing options...
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