Thermal energy is always transmitted from a medium with the higher temperature to one with a lower temperature. This becomes obvious if you consider that heat is the perceptible vibration of molecules (atoms). The stronger the vibration, the higher the perceived temperature. The energy of a molecules vibration can only be transmitted to a neighbouring molecule if that molecule's vibration energy is lower.
The thermal transfer within substances depends on their characteristics.
In the case of dielectric conductors (isolators) the electrons are fixed to the atoms and can therefore not transfer any vibration energy to neighbouring atoms. Instead, the vibration energy is transmitted via the vibrations in the lattice of atoms or molecules.
In the case of conductive substances the vibration energy is transmitted directly via the moveable electrons to the neighbouring atoms, and via the lattice of atoms or molecules. In the case of metals, the proportion of vibration energy transmitted via the electrons is higher than that via lattice vibration. This is also the reason why good electric conductors (such as copper) transmit heat much better than bad conductors (such as iron).
In the case of liquids and gases the vibration energy (heat) is also transmitted via lattice vibration. If, however, the increase in temperature causes a change in density in the liquid or gas, the heat can also be transmitted via convection (e.g.: air circulation), which speeds up the thermal transmission.