1

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.

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.

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:

scheduler = Rufus::Scheduler::PlainScheduler.start_new(:frequency => 3.0)
log = Logger.new('sftp.log')
log.level = Logger::INFO

begin
log.info 'starting sftp'
  Net::SFTP.start(HOST, ID, :password => PW ) do |sftp|
   sftp.dir.glob("./", "20120820*") do |entry|
     puts entry.name
     file = entry.name
     success = sftp.download!(file, file)
   end
  end   
rescue Exception => e
  puts e.message          # Human readable error
  log.error ("SFTP exception occured: " + e.message)
end
scheduler.join
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
user1279586
  • 257
  • 3
  • 16

1 Answers1

7

Does adding :verbose => Logger::DEBUG work ?

Net::SFTP.start(HOST, ID, :password => PW, :verbose => Logger::DEBUG ) do |sftp|
Brian Armstrong
  • 19,707
  • 17
  • 115
  • 144