Downloads a file from the internet using the HTTP, HTTPS or FTP protocol.
InetGet ( "URL", "filename" [, options = 0 [, background = 0]] )
Use the returned handle with InetGetInfo() to determine if there was an error with the download.
The returned handle must be closed with InetClose().
The URL parameter should be in the form "http://www.somesite.com/path/file.html" - just like an address you would type into your web browser.
To use a username and password when connecting simply prefix the servername with "username:password@", e.g.
"http://myuser:mypassword@www.somesite.com"
Notes about the "background" Parameter
By default the function waits until the download has finished before returning. If the background parameter is set to $INET_DOWNLOADBACKGROUND (1) the function returns immediately and the download continues in the background. The function InetGetInfo() can be used to check the status of the download. It takes the handle returned from InetGet().
Multiple downloads are supported if they are started in background mode.
To abort a download call InetClose() and pass it the handle returned by InetGet().
By default AutoIt forces a connection before starting a download. For dial-up users this will prompt to go online or dial the modem (depending on how the system is configured). The options value $INET_FORCEBYPASS (16) disables this behavior. Disabling the behavior can be useful for persistent connects (Broadband, LAN). However, it is also required to work around certain issues in Windows Vista and Windows 7.
FtpSetProxy, HttpSetProxy, HttpSetUserAgent, InetClose, InetGetInfo, InetGetSize, InetRead
#include <InetConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
; InetGet downloads a file in the background.
; The AutoIt script checks in a loop for the download to complete.
Example()
Func Example()
; Save the downloaded file to the temporary folder.
Local $sFilePath= _WinAPI_GetTempFileName (@TempDir )
; Download the file in the background with the selected option of 'force a reload from the remote site.'
Local $hDownload= InetGet ("http://www.autoitscript.com/autoit3/files/beta/update.dat",$sFilePath,$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)
; 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
#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= _WinAPI_GetTempFileName (@TempDir )
; Download the file by waiting for it to complete. Option $INET_FORCERELOAD forces a reload from the remote site.
Local $iBytesSize= InetGet ("http://www.autoitscript.com/autoit3/files/beta/update.dat",$sFilePath,$INET_FORCERELOAD)
; Retrieve the filesize.
Local $iFileSize= FileGetSize ($sFilePath)
; 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 downloaded file.
FileDelete ($sFilePath)
EndFunc ;==>Example