The MsgPlus::DownloadFile function downloads a file asynchronously from an ftp, http or https source and generates an event when the download is complete.
[boolean] DownloadFile( [string] Url, [string,optional] OutFile, [string,optional] User, [string.optional] Password );
A boolean value specifying if the download was initiated. If the returned value is true, an OnEvent_DownloadFileComplete event will be generated once the download operation has completed (whether it succeeds or not). Here is a list of possible reasons why this function may return false:
It is highly recommended to use this function whenever your script needs to download a file. This function returns as soon as the download request has been sent to a different thread of execution, guaranteeing that Messenger will not freeze while the server is being contacted. It is important as various network issues can occur while downloading a file on an external server. If the download is done synchronously with another method, it can result in Messenger freezing for an unspecified amount of time, blocking the user, disturbing Messenger's own network communications and giving the impression that the whole application crashed.
If no path is specified in OutFile, a temporary file will be created and its path will be sent in parameter of OnEvent_DownloadFileComplete. Deleting the temporary file is your responsibility, Messenger Plus! will not do it automatically.
Here is an example that shows how to download a file to check for updates.
function DownloadUpdateFile() { var Started = MsgPlus.DownloadFile("http://server.com/file.txt"); if(Started) Debug.Trace("Downloading file, waiting for event"); else Debug.Trace("Couldn't start the download"); } function OnEvent_DownloadFileComplete(Url, OutFile, Success) { Debug.Trace("DownloadFileComplete event received for " + Url); Debug.Trace(" Success: " + Success); if(Success) { Debug.Trace(" Result file path: " + OutFile); /* Read the file, do what needs to be done */ //Delete the temporary file var File = new ActiveXObject("Scripting.FileSystemObject"); File.DeleteFile(OutFile); } }
Object | MsgPlus |
---|---|
Availability | Messenger Plus! Live 4.20 |