   	{:noreply, state(s, status: status)}
   end
 
-  def handle_info({:ssh_cm, _, {:closed, _}}, state(connection: SSH[_connection: conn], from: from, data: data, status: status) = s) do
+  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

        :gproc_ps.publish(:l, {Hypnotoad.Shell, ref}, """)
        # Uploading #{file} to #{new_path} (temporarily)
        """
        :ok = :ssh_sftp.write_file(sftp_channel, new_path, content)
        :ssh_sftp.stop_channel(sftp_channel)
        S.unlock({Hypnotoad.Host.SSH.Connection, conn})
        :gproc_ps.publish(:l, {Hypnotoad.Shell, ref}, """)
        # Uploading #{file}, moving from #{new_path}

    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, channel: ch)}
  end

  def handle_call({:upload, file, content, ref}, _from, state(connection: SSH[_connection: conn] = ssh) = s) do
