I have a script that pulls pages from our wiki server. It was working
using Net:HTTP and open-uri with basic_authentication, but our
sysadmin disabled basic authentication and left NTLM as the only
authentication method.

Instead of trying to figure out how to use the Ruby NTLM library, I
decide to just use curl. It was working nicely for the HTML pages
using this form:
  def fetch_http_ntlm( url )
    `curl #{url} --ntlm -# -u #{USER}:#{PASS}`
  end

However, the above fails for binary files. (Pulling down images
embedded in pages.) So I had to switch it to this:
  def fetch_http_ntlm( url )
    file_name = "C:\\tmp_#{Time.new.to_i}"
    `curl #{url} --ntlm -# -u #{USER}:#{PASS} -o #{file_name}`
    raw = File.open( file_name, 'rb' ){ |f| f.read }
    File.delete( file_name )
    raw
  end

In other words, I have curl write the output to a file, and then read
in the file using binary mode, and delete the file.

Should I have to do this? Is it a general problem that commands can't
cleanly return binary data to the 'console', and hence can't be
captured using the above format? Or is curl on Windows at fault, and
should be doing something different? Or is Ruby Windows at fault? Or
is Windows itself at fault?


Also - I didn't try using the Tempfile library for the above, since
the documentation for Tempfile.new says:
'Creates a temporary file of mode 0600 in the temporary directory
whose name is basename.pid.n and opens with mode "w+".' If this
documentation is correct, does this mean that the Tempfile library
doesn't work for binary files on Windows?