West Ham United held on to avoid an upset in the Capital One Cup after a 2-1 win at home over League Two side Cheltenham Town.