         :gproc_ps.publish(:l, {Hypnotoad.Shell, ref}, """)
         # Uploading #{file} to #{new_path} (temporarily)
         """
+        S.lock({Hypnotoad.Host.SSH.Connection, conn})
+        {:ok, sftp_channel} = :ssh_sftp.start_channel(conn)
         :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)}
  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, channel: nil

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