     else 
       :ssh_connection.exec(conn, ch, String.to_char_list!("sh /tmp/#{splitter} ; E=$? ; rm -f /tmp/#{splitter}; exit $E"), :infinity)
     end
-  	{:noreply, state(s, from: from, splitter: splitter, ref: ref)}
+  	{:noreply, state(s, from: from, splitter: splitter, ref: ref, channel: ch)}
   end
 
   def handle_call({:upload, file, content, ref}, _from, state(connection: SSH[_connection: conn] = ssh) = s) do

    :gen_server.call(pid, {:download, file, ref}, :infinity)
  end

  defrecordp :state, connection: nil, from: nil, data: "", status: 0, splitter: nil, ref: nil

  def init(SSH[] = ssh) do
    {:ok, state(connection: ssh)}

  	{:noreply, state(s, status: status)}
  end

  def handle_info({:ssh_cm, _, {:closed, _}}, state(connection: SSH[_connection: conn], channel: ch, from: from, data: data, status: status) = s) do
  	data = String.strip(data)
    :gen_server.reply(from, {status, data})
    :ssh_connection.close(conn, ch)
    S.unlock({Hypnotoad.Host.SSH.Connection, conn})
    {:stop, :normal, s}
  end
