title: Ruby Net-SFTP capture and log exceptions
body: <p>I have a simple SFTP script that I am testing to connect to a server and download a file, or files, with a specific date in the file name.</p>
  
  <p>I am using rufus/scheduler to start the SFTP portion of the script every X minutes to see if a new file is on the server.</p>
  
  <p>It all seems to work until I intentionally force an error, such as provide incorrect login credentials. Then I want to be able to capture the exact error or exception and log it using logger.  I am not getting error detail or I am not using rescue correctly:</p>
  
  <pre><code>scheduler = Rufus::Scheduler::PlainScheduler.start_new(:frequency =&gt; 3.0)
  log = Logger.new('sftp.log')
  log.level = Logger::INFO
  
  begin
  log.info 'starting sftp'
    Net::SFTP.start(HOST, ID, :password =&gt; PW ) do |sftp|
     sftp.dir.glob("./", "20120820*") do |entry|
       puts entry.name
       file = entry.name
       success = sftp.download!(file, file)
     end
    end   
  rescue Exception =&gt; e
    puts e.message          # Human readable error
    log.error ("SFTP exception occured: " + e.message)
  end
  scheduler.join
  </code></pre>