class Net::SFTP::Operations::Upload

def process_next_entry

starting point of the state machine.
Examines the stack and determines what action to take. This is the
def process_next_entry
  if @stack.empty?
    if @uploads.any?
      write_next_chunk(@uploads.first)
    elsif !active?
      update_progress(:finish)
    end
    return false
  elsif @stack.last.empty?
    @stack.pop
    @local_cwd = ::File.dirname(@local_cwd)
    @remote_cwd = ::File.dirname(@remote_cwd)
    process_next_entry
  elsif recursive?
    entry = @stack.last.shift
    lpath = ::File.join(@local_cwd, entry)
    rpath = ::File.join(@remote_cwd, entry)
    if ::File.directory?(lpath)
      @stack.push(entries_for(lpath))
      @local_cwd = lpath
      @remote_cwd = rpath
      @active += 1
      update_progress(:mkdir, rpath)
      request = sftp.mkdir(rpath, &method(:on_mkdir))
      request[:dir] = rpath
    else
      open_file(lpath, rpath)
    end
  else
    open_file(@stack.pop.first, remote)
  end
  return true
end