I am looking for a code review on this class. I found myself writing this logic a lot, so trying to save myself some time.
require 'etc'
require 'net/ssh'
require 'net/scp'
class SSHOps
def initialize(host, user=Etc.getlogin, *args)
@host = host
@user = user
@keys = args.empty? \
? args << Etc.getpwnam(Etc.getlogin).dir + '/.ssh/id_rsa' \
: args
end
##
# Download a file over SCP.
#
# ==== Attributes
#
# * +hostname+ - Target hostname to download the file from.
# * +filename+ - Filename to download.
def download_file(remote_path, local_path)
ssh = Net::SSH.start(@host, @user, :keys => @keys)
ssh.scp.download(remote_path, local_path, :preserve => true)
ssh.close
end
end