First of all, I wasn't 100% sure what you meant by cog rail. A
cog railway is a railway in the mountains or going up a hill. It has cogs and the locomotive has a cogwheel, thus ensuring traction.
Maybe you can partially explain what it is:
tranvía dentada
tranvía con dientes
tren con rueda dentada
tren de montaña con rueda dentada
un tren cog railway con rueda dentada para subir la pendiente
I don't know if any of those sound good in Spanish
winding it's way up the hill side
El tren culebreaba de lado a lado mientras subía la colina/pendiente/ladera.