Jump to content

Download Function add timeout


Recommended Posts

Hi,

EDIT: done

$FileURL = "http://site.de/file.txt"
$FileName = @TempDir & "\file.txt"
$Downloadtimeout = 60000
$INET_DOWNLOADBACKGROUND = 1
$INET_DOWNLOADCOMPLETE = 2

Func Download($FileURL, $FileName, $Downloadtimeout)
    Local $hDownload = InetGet($FileURL, $FileName, 19, $INET_DOWNLOADBACKGROUND)

    $begin = TimerInit()
    Do
        Sleep(250)
        $fDiff = TimerDiff($begin)
        If ($fDiff > $Downloadtimeout) Then
            InetClose($hDownload)
            ExitLoop
        EndIf
    Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
    ; Retrieve details about the download file.
    Local $aData = InetGetInfo($hDownload)
    If @error Then
        FileDelete($FileName)
        Return False ; If an error occurred then return from the function and delete the file.
    EndIf
    InetClose($hDownload)
EndFunc   ;==>Download

Download($FileURL, $FileName, $Downloadtimeout)

 

 

Edited by marabunta
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...