Jump to content
Muhammad_Awais_Sharif

InetGet correct way of checking error during downloading a file

Recommended Posts

Muhammad_Awais_Sharif

I am using this code to Download a file 
I don't know correct way of checking error during downloading

Global $DownloadStatus = InetGet($url, $fileName, Default, $INET_DOWNLOADBACKGROUND)

While 1
    $ArrayOFDownloadStatuts = InetGetInfo($DownloadStatus)
    If Not $ArrayOFDownloadStatuts[4] = 0 Then
            MsgBox(0,"Error","Error During Downloading")
            ExitLoop
    EndIf
    If $ArrayOFDownloadStatuts[2] Then
            MsgBox(0,"","Compelted")
            ExitLoop
    EndIf
WEnd

I am using that code but don't know why it gives error during downloading the file 

is it wrong way of checking error or is there network error on my pc ? :P 
thank you :D 

Share this post


Link to post
Share on other sites
ahmet

From help file:   fifth element (at index 4) - The error value for the download. The value itself is arbitrary. Testing that the value is non-zero is sufficient for determining if an error occurred - so I assume that if that element has value of zero than there is no error. You could also do something like this:

$ArrayOFDownloadStatuts = InetGetInfo($DownloadStatus)
If @error Then
;do something
EndIf

Share this post


Link to post
Share on other sites
Muhammad_Awais_Sharif

thanks for suggestion :D 

Share this post


Link to post
Share on other sites
ahmet

You are welcome :D

  • Like 1

Share this post


Link to post
Share on other sites
falcontechnics

$ArrayOFDownloadStatuts = InetGetInfo($hDownload)
        If $ArrayOFDownloadStatuts[3] = True Then
          MsgBox (0,"", "OK")
        Else
          MsgBox (0, "", "not ok")
        EndIf
                       
        InetClose($hDownload)

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

  • Similar Content

    • Tersion
      By Tersion
      Why I can't get more than two simultaneously background downloads?
      Simultaneously background downloads with InetGet() works! It was just server limitation from which I downloaded files.
    • Gowrisankar
      By Gowrisankar
      Dear members of the forum,
      I need to open the attachments from mails without downloading them. Is it possible using OutlookEx UDF ?
    • leb
      By leb
      Hello there,
      I am using the function InetGet example in the help files on a website and getting the error 13. First, I searched the help files and the forum for a list of errors to consult to no avail. I suspect this is a 400's server reply based error but it would be nice to get more info about it.
      Please help, thanks.
      L
    • Dante_t
      By Dante_t
      Hi Guys, I need help. I have searched the forum before posting and i couldn't find anything. The code below works fine when downloading files from "http" sites, but when trying to download from "https" sites, no files are downloaded. I tried different sites and I experience the same problem everywhere. Is there something I'm missing or doing wrong? Please note that I'm not a programmer and I'm new to this. I'm just using logic wherever i can to get things done. your help will be highly appreciated.
       
      #include <InetConstants.au3>
      #include <MsgBoxConstants.au3>
      #include <WinAPIFiles.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 = "d:\"
          ; Download the file in the background with the selected option of 'force a reload from the remote site.'
          Local $hDownload = InetGet("https://en.wikipedia.org/wiki/HTTPS#/media/File:Internet2.jpg", $sFilePath& "Internet2.jpg", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
          ; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True.
          Do
              Sleep(250)
          Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
          ; Retrieve the number of total bytes received and the filesize.
          Local $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD)
          Local $iFileSize = FileGetSize($sFilePath&"Internet2.jpg")
          ; Close the handle returned by InetGet.
          InetClose($hDownload)
          ; 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)
          ; Delete the file.
          ;FileDelete($sFilePath)
      EndFunc   ;==>Example
       
    • swatsapkraz
      By swatsapkraz
      First script here. Thanks for taking the time.
      I want to download a file from my dropbox or other cloud file host and I want autoit to read the file and proceed.
      Here are the references I've gone through, it's just I'm not familiar yet with autoit so I'm looking for advice:
      https://www.autoitscript.com/autoit3/docs/functions/InetGet.htm
      https://www.autoitscript.com/autoit3/docs/functions/FileRead.htm
       
      How would I start out downloading a text file from dropbox and if in the file there is a 1 then it will proceed with the rest of the script if there is a 0 or if the file cannot be downloaded I want it to just end.
       
      Thank you for taking the time to read this and I apologize in advance if this seems very trivial for some but this is my first script and I'm hoping this is the correct place to ask this question.
×