InetGet

首页  后退  前进

InetGet
down2

InetGet

使用 HTTP,HTTPS 或 FTP 协议下载文件.

 

InetGet ( "URL", "filename" [, options = 0 [, background = 0]] )

参数

URL

下载文件的 URL(地址). 见备注

filename

下载到本地的文件名称

options

[可选] $INET_LOCALCACHE (0) = 如有可能则从本地缓存中获取文件 (默认).

   $INET_FORCERELOAD (1) = 强制从远程站点重新加载.

   $INET_IGNORESSL (2) = 忽略所有 SSL 错误(使用 HTTPS 连接时).

   $INET_ASCIITRANSFER (4) = 使用 FTP 协议传输 ASCII 文件(不能和标志 $INET_BINARYTRANSFER (8) 一起使用).

   $INET_BINARYTRANSFER (8) = 使用 FTP 协议传输二进制文件(不能和标志 $INET_ASCIITRANSFER (4) 一起使用). 这是默认传输方式.

   $INET_FORCEBYPASS (16) = 强制在线连接 (见备注).

 

常量定义在 InetConstants.au3

background

[可选]

   $INET_DOWNLOADWAIT (0) = 等待下载完成之后执行脚本后面的语句 (默认).

   $INET_DOWNLOADBACKGROUND (1) = 立即返回并在后台完成下载 (见备注).

常量定义在 InetConstants.au3

返回值

成功:

返回值取决于是否使用后台下载:

后台下载: 返回句柄.

等待下载: 返回下载的字节数.

失败:

后台下载: 返回句柄.

等待下载: 返回 0, @error 设置 为非 0 值.

备注

必须 Internet Explorer 3 或更高版本.

 

使用返回的句柄和 InetGetInfo() 函数确定是否有下载错误.

返回的句柄必须使用 InetClose() 函数关闭.

 

URL 参数的形式: "http://www.somesite.com/path/file.html" - 如同在网页浏览器中输入的地址.

 

指定用户名及密码,只要在服务器前加 "用户名:密码@", 例如:

"http://myuser:mypassword@www.somesite.com"

 

 

关于 background 参数的说明

 

函数默认等待, 直到下载完毕才返回. 如果 background 参数设置为 $INET_DOWNLOADBACKGROUND (1), 函数立即返回, 并在后台继续下载.

此时可传递 InetGet() 返回的句柄到 InetGetInfo() 函数检查下载的状态.

 

后台下载模式支持多文件下载.

 

要终止下载, 传递 InetGet() 返回的句柄到 InetClose().

 

默认 AutoIt 开始下载前强制连接. 对于拨号上网用户将提示联机或调制解调器拨号(取决于系统配置而定). 选项值 $INET_FORCEBYPASS (16) 将禁用此行为.

对于宽带, 局域网的持久性连接, 禁用的行为会很有用.

但也需要解决 Windows Vista 与 Windows 7 的某些问题.

 

函数示例

示例 1

#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 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

示例 2

#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. The option of 'get the file from the local cache' has been selected.
    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 file.
    FileDelete($sFilePath)
EndFunc   ;==>Example

----------------------------------------

 

该函数可以通过命令调用 exect

参见:

InetGetSize, InetRead, InetGetInfo, InetClose, HttpSetProxy, FtpSetProxy, HttpSetUserAgent

例子
copy

exect=InetGet('http://www.mozilla.org',@DesktopDir&'\mozilla.html') ;;在桌面上下载页面

 

exect=$var_h=InetGet('http://www.mozilla.org',@DesktopDir&'\mozilla.html',1,1)||Sleep(1000)||$var_a=InetGetInfo($var_h,-1)||_ViewValues($var_a)||InetClose($var_h) ;; 下载页面并提供信息

up2

tcimage © Аверин Андрей для Total Commander Image Averin-And@yandex.ru