I am trying to write a rake task where it automatically connect to an Experian Host using sftp.
The guy from Experian gave me this command to connect to their sever by using SFTP:
sftp -o PreferredAuthentications=password -o PubkeyAuthentication=no username@experian_ip
which works just fine when I run it on the terminal.
I then wrote a rake task based on that command:
require 'net/sftp'
task :experian_sts => [:environment] do
hostname = "experian_ip"
username = "username"
password = "password"
@cmd = "test"
begin
sftp = Net::SFTP.start(hostname, username, password: password, keys_only: false, number_of_password_prompts: 0)
res = sftp.exec!(@cmd)
sftp.close
puts res
rescue
puts "Unable to connect to #{hostname} using #{username}/#{password}"
end
end
But the task just doesn't seems to work. Any help?
UPDATE
After removing rescue to see the error:
rake aborted!
Net::SSH::Disconnect: disconnected: Too many bad authentication attempts! (11)
/Users/ryzal/Sites/rentlord/lib/tasks/experian_sts.rake:12:in `block in <top (required)>'
/Users/ryzal/.rbenv/versions/2.3.1/bin/bundle:22:in `load'
/Users/ryzal/.rbenv/versions/2.3.1/bin/bundle:22:in `<main>'
Tasks: TOP => experian_sts
(See full trace by running task with --trace)