Possible Duplicate:
Downloading files without using Import

While attempting to answer my own question I realized that I don't know a way to simply download a binary file to a specified folder with Mathematica, bypassing any Import/Export processing.

One can Import as "Binary" but this uses several times the amount of memory that the file takes to store. Further, the entire file must be loaded into memory and then processed with Export. Is there some way to pipe or stream the file as it is downloaded directly to disk?

One solution would be if it were possible to directly OpenRead a URL and access the file as a stream, and/or read only a specified byte range within the file. Neither of these are apparently possible with the native tools. Perhaps a JLink program can be made that would allow similar functionality? What would that entail? (I don't write Java and therefore rarely use JLink.)


marked as duplicate by Leonid Shifrin, Mr.Wizard Oct 3 '12 at 13:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 4
    $\begingroup$ Simple way? Use curl or wget :) $\endgroup$ – rm -rf Oct 3 '12 at 7:09
  • $\begingroup$ @rm I think I ended up with two questions in one here: (1) download to folder (2) stream-type access of internet resource. Do you think I should split them? $\endgroup$ – Mr.Wizard Oct 3 '12 at 7:28
  • $\begingroup$ I don't think so... they both are related in the sense that answering 2 will answer 1. Better to have it in one place. This is definitely an area where mma is lacking, but I'm actually ok with it (it can't toast my bread either... or can it?). I've been meaning to ask a related question myself — on how to output multipage pdfs... I've been fiddling with the "Pages" option in Export, but seems like I'm using the wrong syntax. Will ask if I make no headway in a few days $\endgroup$ – rm -rf Oct 3 '12 at 7:37
  • 1
    $\begingroup$ If you were ever considering writing Java then you'd have to ask what the benefit would be versus running wget or curl (out of the box so-to-speak) from within Mma using Run. The added advantage of wget is that you can download from URLs with cookies and logins etc. $\endgroup$ – Mike Honeychurch Oct 3 '12 at 8:38