Sign in to follow this  
Followers 0
rich2323

InetGet weirdness

7 posts in this topic

Having a weird issues where I am trying to download a file using inetget and on 1/2 the machines its working on the other 1/2 is not. I then run the script again on the machines that did not work and it works. The machines that are failing are all connected to a reliable intenet connection. I searched through the forums and have not been able to find anything. What I am trying to understand what typcially causes the Inetget command to Fail? What is the best method to troubshoot inetget fails?

Pulling my hair out over here. Please help.

Thanks,

Rich

ConsoleWrite("Downloading iTunes ....")
        TraySetToolTip("Downloading updates iTunes....")
        FileDelete("C:\it\itunessetup")

        ;;; download itunes package from troy

        DirCreate("C:\IT\iTunesSetup")
        DirCreate("C:\iTunes")

        ProgressOn('Downloading', 'Downloading', 'iTunes download', 10, 10)

        Local $file_url = "http://mywebsite/itunes/itunesinstallfiles.exe" ; download file from
        Local $iDownload = InetGet($file_url, "C:\it\installer\itunesinstallfiles.exe", 1, 1)
        $size = InetGetSize($file_url, 1)

        Do
            Sleep(250)
            $aData = InetGetInfo($iDownload)
            ProgressSet((InetGetInfo($iDownload, 0) / $size) * 100)
        Until InetGetInfo($iDownload, 2)

        $aData = InetGetInfo($iDownload) ; Get all information.

        Local $aData = InetGetInfo($iDownload)
        InetClose($iDownload)
        ProgressOff()

Share this post


Link to post
Share on other sites



Local $file_url = "http://mywebsite/itunes/itunesinstallfiles.exe"

Local $InstallFolder = "C:\IT\Installer"

If FileExists($InstallFolder) Then DirRemove($InstallFolder, 1)

DirCreate($InstallFolder)

ProgressOn('Downloading', 'Downloading', 'iTunes download', 10, 10)

Local $size = InetGetSize($file_url, 1)

Local $iDownload = InetGet($file_url, $InstallFolder & "\itunesinstallfiles.exe", 1, 1)

Do
    Sleep(250)
    ProgressSet((InetGetInfo($iDownload, 0) / $size) * 100)
Until InetGetInfo($iDownload, 2)

Local $aData = InetGetInfo($iDownload)

InetClose($iDownload)

ProgressOff()

; from helpfile - $aData is an array
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)


Make yourself sheep and the wolves will eat you - Benjamin Franklin

Share this post


Link to post
Share on other sites

Thanks for the comment. I figured out that I was recycling some of my variables for other downloads(which I have done in the past without an issue) and this must have been causing the issue. I made new variable for each download, and it seems like the issue went away.

Thanks for your help.

Rich

Share this post


Link to post
Share on other sites

Hi

I am struggling with similar issue. I am on IE8, win XP sp3 and using inetget(), unable to download the complete file. It just downloads 17 KB out of 96 KB. 

here is my code-

#include <IE.au3>
#Include <Date.au3>

Local $oPgm, $oSubmit, $oExportExcel, $oDest
Local $sPgm = "Re engineering"
Local $sUrl = "SOME URL"
Local $oDest = "D:CR"
Local $oIE = _IECreate($sUrl, 1)

_IELoadWait($oIE)

$oInputs = _IETagNameGetCollection($oIE, "input")
for $oInput in $oInputs
    if $oInput.type = "text" And $oInput.name = "ctl00$ContentPlaceHolder1$ProgrammeTextBox" Then $oPgm = $oInput
   if $oInput.type = "submit" And $oInput.value = "FIND" Then $oSubmit = $oInput
    if isObj($oPgm) And isObj($oSubmit) then exitloop
Next

$oPgm.value = $sPgm
_IEAction($oSubmit, "click")

_IELoadWait($oIE)

$oInputs = _IETagNameGetCollection($oIE, "input")
for $oInput in $oInputs   
   if $oInput.type = "image" And $oInput.name = "ctl00$ContentPlaceHolder1$btnExport" Then $oExportExcel = $oInput
    if isObj($oExportExcel) then exitloop
Next

_IEAction($oExportExcel, "click")
_IELoadWait($oIE)

; Save the downloaded file to the folder.
Local $sFilePath = $oDest & "Change Register.xlsx"

ProgressOn('Downloading', 'Downloading', 'Excel download', 10, 10)

Local $size = InetGetSize($sURL, 1)

; Advanced example - downloading in the background
Local $hDownload = InetGet($sURL, $sFilePath, 1, 1)

Do
    Sleep(250)
    ProgressSet((InetGetInfo($hDownload, 0) / $size) * 100)
Until InetGetInfo($hDownload, 2)

Local $aData = InetGetInfo($hDownload)

InetClose($hDownload)

ProgressOff()

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)

 

Can you please point out why it is just downloading 1/5th of the file? when the file is later opened, it says the file is corrupt.

If i go to the URL and download the file, it works perfectly fine.

regards

Adarsh

Share this post


Link to post
Share on other sites

Try this Code

#include <Math.au3>

$jDll = DllOpen("Wininet.dll")

$Buffer = Inet_Read("http://download.winzip.com/winzip16-32.exe",1000)
$BufferData = DllStructGetData($Buffer,1)
$fo = FileOpen("winzip16-32.exe",2)
FileWrite($fo,Binary($BufferData))
FileClose($fo)

Func Inet_Read($lpszUrl,$ByteAtaTime)
if ($ByteAtaTime <= 0) Then Return SetError(1,0,0)
$HIntOpen = InternetOpen("OPEN")
if Not ($HIntOpen) Then Return SetError(2,0,0)
$HIntOpenUrl = InternetOpenUrl($HIntOpen,$lpszUrl,"",0,0,0)
if Not ($HIntOpenUrl) Then Return SetError(3,0,0)
$FileSize = HttpQueryInfo($HIntOpenUrl,5)
if @error Then Return SetError(4,0,0)
$Buffer = DllStructCreate("BYTE Buffer[" & $FileSize & "]")
$lpBuffer = DllStructGetPtr($Buffer)
$FileSize = Number($FileSize)
Local $MovePos = 0
While 1
$OutPtr = $lpBuffer + $MovePos
$dwNumberOfBytesToRead = _Min($ByteAtaTime,$FileSize - $MovePos)
$lpdwNumberOfBytesRead = InternetReadFile($HIntOpenUrl,$OutPtr,$dwNumberOfBytesToRead)
$error = @error
if $error Or $lpdwNumberOfBytesRead <= 0 Then ExitLoop
$MovePos += $lpdwNumberOfBytesRead
WEnd
if ($error) Then $error = 5
InternetCloseHandle($HIntOpen)
InternetCloseHandle($HIntOpenUrl)
Return SetError($error,0,$Buffer)
EndFunc


Func InternetReadFile($hFile,$lpBuffer,$dwNumberOfBytesToRead)
$DLLSDWORD = DllStructCreate("DWORD")
$lpdwNumberOfBytesRead = DllStructGetPtr($DLLSDWORD)
$BOOL = DllCall($jDll,"BOOL","InternetReadFile","HANDLE",$hFile,"ptr",$lpBuffer, _
"DWORD",$dwNumberOfBytesToRead,"ptr",$lpdwNumberOfBytesRead)
if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0)
Return SetError(0,0,DllStructGetData($DLLSDWORD,1))
EndFunc

Func HttpQueryInfo($hRequest,$dwInfoLevel,$lpdwIndex = 0)
Local $lpdwBufferLength = 1000
$DLLSDWORD = DllStructCreate("DWORD")
DllStructSetData($DLLSDWORD,1,$lpdwBufferLength)
$LPDWORDLENGTH = DllStructGetPtr($DLLSDWORD)
$DLLSlpvBuffer = DllStructCreate("WCHAR[" & $lpdwBufferLength & "]")
$lpvBuffer = DllStructGetPtr($DLLSlpvBuffer)
$BOOL = DllCall($jDll,"BOOL","HttpQueryInfoW","HANDLE",$hRequest,"DWORD",$dwInfoLevel, _
"ptr",$lpvBuffer,"ptr",$LPDWORDLENGTH,"DWORD",$lpdwIndex)
if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0)
Return SetError(0,0,DllStructGetData($DLLSlpvBuffer,1))
EndFunc

Func InternetOpenUrl($hInternet,$lpszUrl,$lpszHeaders,$dwHeadersLength,$dwFlags,$dwContext)
$HINTERNET = DllCall($jDll,"HANDLE","InternetOpenUrlW","HANDLE",$hInternet,"wstr",$lpszUrl, _
"wstr",$lpszHeaders,"DWORD",$dwHeadersLength,"DWORD",$dwFlags,"ptr",$dwContext)
if @error Then Return SetError(1,0,0)
if @error Or Not ($HINTERNET[0]) Then Return SetError(1,0,0)
Return SetError(0,0,$HINTERNET[0])
EndFunc

Func InternetOpen($lpszAgent,$dwAccessType = 0,$lpszProxyName = "",$lpszProxyBypass = "",$dwFlags = 0)
$HINTERNET = DllCall($jDll,"HANDLE","InternetOpenW","wstr",$lpszAgent,"DWORD",$dwAccessType, _
"wstr",$lpszProxyName,"wstr",$lpszProxyBypass,"DWORD",$dwFlags)
if @error Or Not ($HINTERNET[0]) Then Return SetError(1,0,0)
Return SetError(0,0,$HINTERNET[0])
EndFunc

Func InternetCloseHandle($hInternet)
$BOOL = DllCall($jDll,"BOOL","InternetCloseHandle","HANDLE",$hInternet)
if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0)
Return SetError(0,0,$BOOL[0])
EndFunc

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

Tx Universalist

Will your code work when the machine is locked?

Share this post


Link to post
Share on other sites

Tx Universalist

Will your code work when the machine is locked?

 

If you waited longer before answering it would be more fun

Only half of your teeth before eating well and slept well and

will work code While the device is shut down


صرح السماء كان هنا

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0