title: How can you tell if an FTP file exists using ruby?
body: <p>I'm trying to figure out the best and fastest way to tell if a file exists on an ftp server.</p>
  
  <p>This is what I came up with...</p>
  
  <pre><code>def remote_exists?(idx)
    #@file.rewind if @file.eof?
    ftp = Net::FTP.new(FTP_SERVER)
    ftp.login
    begin
      ftp.size(idx)
    rescue Exception
      return false
    end
    true
  end
  </code></pre>
  
  <p>It seems like just capturing every exception is a bad idea but I had trouble getting the correct specific exception(s).</p>
  
  <p>I'm also using <a href="http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/" rel="noreferrer">OpenURI</a> in my code to actually get the file.  I was trying to figure out if that might have some method that might be better but I think it just uses Net::FTP anyway.</p>