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