From: khaines@... Date: 2006-08-16T03:25:41+09:00 Subject: Re: FileTest.exists? over HTTP On Wed, 16 Aug 2006, Neil Charlton wrote: > HI > > I would like to test for the existence of a file over HTTP. I have tried > various combinations of File.stat and FileTest.exists? with no results. > > For example (image.jpg exists) > > if FileTest.exists?("http://domain.com/image.jpg") > puts "found file" > end > > does not print found file even though the file exists > > What am I doing wrong ? Using FileTest.exists?() for an HTTP operation. By default, Ruby doesn't try to make file operations transparently work over HTTP, except for the availability of the open-uri in the ruby core, which lets one use Kernel::open() to open http, https, and ftp URIs. The easiest way, I think, to get the simple effect you are looking for is to use open-uri. require 'open-uri' begin open("http://domain.com/image.jpg") rescue OpenURI::HTTPError # It couldn't be accessed, so do something. end Kirk Haines