Download

インターネットからファイルをダウンロードします。

Download URL, Filename 

パラメータ

URL

型:文字列

ダウンロードするファイルのURL。For example, "https://someorg.org" might retrieve the welcome page for that organization.

Filename

型:文字列

ローカルに作成するファイル名を指定します。絶対パスが指定されていない場合は、A_WorkingDirにあると仮定されます。Any existing file will be overwritten by the new file.

ファイルへダウンロードする機能です。To download to a variable instead, see the example below.

エラー処理

失敗した場合は例外がスローされます。

備考

リモートファイルが存在しないのに、ダウンロードが成功したように見えることがあります。これは、多くのウェブサーバーが、見つからないファイルの代わりにエラーページを送信するためです。このエラーページは、Filenameの代わりに保存されるものです。

ファイアウォールや複数のネットワークアダプターが存在する場合、この機能に失敗することがあります。また、ウェブサイトによっては、そのようなダウンロードをブロックしている場合があります。

Caching: By default, the URL is retrieved directly from the remote server (that is, never from Internet Explorer's cache). キャッシュを許可する場合は、URLの前に*0とスペースを入れてください:"*0 https://someorg.org". アスタリスクに続くゼロは、有効なdwFlags番号で置き換えることができます。詳細は、www.microsoft.com「InternetOpenUrl」を検索してください。

Proxies: If a proxy server has been configured in Microsoft Internet Explorer's settings, it will be used.

FTPやGopherのURLもサポートされています。事例:

Download "ftp://example.com/home/My File.zip", "C:\My Folder\My File.zip" ;匿名でログインします。
Download "ftp://user:pass@example.com:21/home/My File.zip", "C:\My Folder\My File.zip" ;特定のユーザーでログインしてください。
Download "ftp://user:pass@example.com/My Directory", "C:\Dir Listing.html" ; HTML形式のディレクトリ一覧を取得します

FileRead, FileCopy

テキストファイルをダウンロードします。

Download "https://www.autohotkey.com/download/2.0/version.txt", "C:\AutoHotkey Latest Version.txt"

ZIPファイルをダウンロードします。

Download "https://someorg.org/archive.zip", "C:\SomeOrg's Archive.zip"

テキストを変数にダウンロードします。

whr := ComObject("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "https://www.autohotkey.com/download/2.0/version.txt", true)
whr.Send()
上記の'true'と下記の呼び出しを使用することで、スクリプトの応答性を維持することができます。
whr.WaitForResponse()
version := whr.ResponseText
MsgBox version

Makes an asynchronous HTTP request.

req := ComObject("Msxml2.XMLHTTP")
; asyncを有効にしてリクエストをオープンします。
req.open("GET", "https://www.autohotkey.com/download/2.0/version.txt", true)
; コールバック関数を設定します。
req.onreadystatechange := Ready
; リクエストを送信します。  完了したらReady()が呼ばれる。
req.send()
/*
; 待つのであれば、onreadystatechangeは必要ない。
; async=trueを設定し、このように待機することで、スクリプトが残ります。
; async=falseの場合、ダウンロードが行われている間、レスポンシブに動作します。
; すると、スクリプトが応答しなくなります。
while req.readyState != 4
    sleep 100
*/
Persistent

Ready() {
    if (req.readyState != 4)  ; Not done yet.
        return
    if (req.status == 200) ; OK.
        MsgBox "Latest AutoHotkey version:" req.responseText
    else
        MsgBox "Status " req.status,, 16
    ExitApp
}