Downloads

Another common need in scripting is to download a file from somewhere, and the file can be a binary or text, and it can be just saved to a HDD, or processed first (ideally w/o any temporary files).

There are many ways to do it XSharper.

A dedicated download command, saving to a file.

<download from="http://www.xsharper.com/xsharper.exe" to="x.exe" />

Via a dedicated download command, saving to a variable as text:

<download from="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" to="x" />
<print>Length of downloaded string is ${=$x.length} characters</print>

ftp and http are supported, including their ftps:// and https:// variations. There is also a special scheme ftpa:// meaning "active ftp", as opposed to default passive ftp.

While download action is useful, it may be sometimes more to use URLs for remote files in the same way as local filenames are used.

<!-- count how many times word appendTo is mentioned in jquery -->
<set url="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" />
<readtext from="${url}" outTo="jq" />
<set cnt="${0}" />
<regex pattern="\bappendTo\b" value="${jq}">
	<set cnt ="${= $cnt +1 }" />
</regex>
<print>Count (interpreted) =${cnt}</print>

<!-- all of the above in a single C# line -->
<?_ 
	c.WriteLine("Count (C#) = {0}", 
		new Regex("\\bappendTo\\b").Matches(c.ReadText(c.GetStr("url"))).Count); ?>

<!-- all of the above in a single interpreted line -->
<print>Count (XSharper) = ${=new Regex('\bappendTo\b').Matches(c.ReadText(c["url"])).Count }</print>