I don't see much reason to worry about this method's length. At least not right now - if you add more event handling, yeah, it might become a little cumbersome. But for what it does now, there's no pressing need to do anything.
I would recommend more whitespace, though. There's no reason to compress,every,line,that,has,commas,in,it. Just makes it harder to read.
I'm also fairly sure that the
:finished event is actually called
Structurally, just for the sake of it, you could do something like:
attr_reader :host, :user, :password
def initialize(host, user, password)
@host = host
@user = user
@password = password
def upload(local_file_path, remote_file_path)
Net::SFTP.start(host, user, password: password) do |sftp|
sftp.upload!(local_file_path, remote_file_path) do |event, uploader, *args|
send(event, uploader, *args) if respond_to?(event, true)
def open(uploader, *args)
def close(uploader, *args)
def finish(uploader, *args)
Basically, we're handling events with methods instead of a
case block. I've added the
close method/event handler as an example.