<doc>
  <legacy_id>1423</legacy_id>
  <name>libURLDownloadToFile</name>
  <type>command</type>
  <syntax>
    <example>libURLDownloadToFile <i>downloadURL</i>,<i>filePath</i>[,<i>callbackMessage</i>]</example>
  </syntax>
  <library>Internet library</library>
  <objects>
  </objects>
  <synonyms>
  </synonyms>
  <classification>
    <category>Networks &amp; Communication</category>
    <category>Standalone Applications</category>
  </classification>
  <references>
    <keyword tag="ftp">ftp Keyword</keyword>
    <command tag="libURLftpUploadFile">libURLftpUploadFile Command</command>
    <command tag="libURLSetFTPStopTime">libURLSetFTPStopTime Command</command>
    <command tag="libURLSetStatusCallback">libURLSetStatusCallback Command</command>
    <command tag="load">load Command</command>
    <command tag="put">put Command</command>
    <command tag="unload">unload Command</command>
    <function tag="URLStatus">URLStatus Function</function>
    <command tag="libURLFollowHttpRedirects">libURLFollowHttpRedirects Command</command>
  </references>
  <history>
    <introduced version="2.0">Added.</introduced>
  </history>
  <platforms>
    <mac/>
    <windows/>
    <linux/>
    <ios/>
    <android/>
  </platforms>
  <classes>
    <desktop/>
    <server/>
    <web/>
    <mobile/>
  </classes>
  <security>
    <network/>
  </security>
  <summary><glossary tag="download">Downloads</glossary> a file from an Internet <glossary tag="server">server</glossary> asynchronously via FTP, HTTP or HTTPS</summary>
  <examples>
    <example>libURLDownloadToFile "ftp://example.org/new_beta",it</example>
    <example>libURLDownloadToFile myFile,newPath,"downloadComplete"</example>
  </examples>
  <description>
    <p>Use the <b>libURLDownloadToFile</b> <glossary tag="command">command</glossary> to <glossary tag="download">download</glossary> a <keyword tag="file">file</keyword> from an FTP Server or Web Server. </p><p/><p><b>Parameters:</b></p><p>The <i>downloadURL</i> specifies the <glossary tag="server">server</glossary> and file to download, in the form of an FTP, HTTP or HTTPS url.</p><p/><p>The <i>filePath</i> specifies the <glossary tag="file path">name and location</glossary> to save the downloaded file in. If you specify a name but not a location, LiveCode assumes the <keyword tag="file">file</keyword> is in the <property tag="defaultFolder">defaultFolder</property>.</p><p/><p>The <i>callbackMessage</i> is the name of a <keyword tag="message box">message</keyword> to send after the download is finished.</p><p/><p><b>Comments:</b></p><p>The <b>libURLDownloadToFile</b> <glossary tag="command">command</glossary> transfers the data directly from the <keyword tag="file">file</keyword> to the <glossary tag="server">server</glossary>. Unlike simply using the <command tag="put">put</command> <glossary tag="command">command</glossary> to put the contents of a <keyword tag="URL">URL</keyword> into a <keyword tag="file">file</keyword>, using the <b>libURLDownloadToFile</b> <glossary tag="command">command</glossary> does not load all the data into memory at once, so this <glossary tag="command">command</glossary> is a better choice for large <function tag="files">files</function>.</p><p/><p>The <b>libURLDownloadToFile</b> <glossary tag="command">command</glossary> transfers the file in <glossary tag="binary">binary</glossary> mode.</p><p/><p>The <i>callbackMessage</i> is sent to the <glossary tag="object">object</glossary> whose <property tag="script">script</property> contains the <b>libURLDownloadToFile</b> <glossary tag="command">command</glossary>, after the <glossary tag="download">download</glossary> is complete, so you can handle the <i>callbackMessage</i> to perform any tasks you want to delay until the file has been <glossary tag="download">downloaded</glossary>. Two <glossary tag="parameter">parameters</glossary> are sent with the <keyword tag="message box">message</keyword>: the <keyword tag="URL">URL</keyword> and the <function tag="URLStatus">URLStatus</function> of the <keyword tag="file">file</keyword>.</p><p/><p><img src="202651"/> <b>Tip:</b> On <glossary tag="Mac OS">Mac OS</glossary> and <glossary tag="OS X">OS X systems</glossary>, the new <glossary tag="file">file's</glossary> <glossary tag="creator signature">creator signature</glossary> and <glossary tag="type signature">file type</glossary> is set to the value specified in the <property tag="fileType">fileType</property> <glossary tag="property">property</glossary>.</p><p/><p><img src="202653"/> <b>Important! </b> The <b>libURLDownloadToFile</b> <glossary tag="command">command</glossary> is part of the <glossary tag="Internet library">Internet library</glossary>. To ensure that the <glossary tag="command">command</glossary> works in a <glossary tag="standalone application">standalone application</glossary>, you must include this <glossary tag="LiveCode custom library">custom library</glossary> when you create your <glossary tag="standalone application">standalone</glossary>. In the Inclusions section of the <glossary tag="Standalone Application Settings">Standalone Application Settings</glossary> window, make sure "Internet Library" is selected in the list of script libraries.</p><p/><p><b>Note:</b> When included in a <glossary tag="standalone application">standalone application</glossary>, the <glossary tag="Internet library">Internet library</glossary> is implemented as a hidden <command tag="group">group</command> and made available when the <command tag="group">group</command> receives its first <message tag="openBackground">openBackground</message> message. During the first part of the <glossary tag="application">application's</glossary> startup process, before this <keyword tag="message box">message</keyword> is sent, the <b>libURLDownloadToFile</b> <glossary tag="command">command</glossary> is not yet available. This may affect attempts to use this <glossary tag="command">command</glossary> in <message tag="startup">startup</message>, <message tag="preOpenStack">preOpenStack</message>, <message tag="openStack">openStack</message>, or <message tag="preOpenCard">preOpenCard</message> <glossary tag="handler">handlers</glossary> in the <glossary tag="main stack">main stack</glossary>. Once the <glossary tag="application">application</glossary> has finished starting up, the <command tag="start using">library</command> is available and the <b>libURLDownloadToFile</b> <glossary tag="command">command</glossary> can be used in any <glossary tag="handler">handler</glossary>.</p><p/><p><b>Cross-platform note:</b> On iOS and Android <b>libURLDownloadToFile</b> is blocking until the download is complete. Completion of the download is notified by the <message tag="urlProgress">urlProgress</message> message, where you can test if the <i>downloaded</i> status is set.</p>
  </description>
</doc>