Promoted to captain of U.S. engineers, Foster was in command of the garrison at Fort Moultrie when the Civil War began. He immediately transferred his small force to Fort Sumter and became second-in-command to Maj. Robert Anderson during the Battle of Fort Sumter. Foster was appointed a brigadier general of volunteers on October 23, 1861, and commanded the 1st Brigade in Maj. Gen. Ambrose Burnside's North Carolina Expedition. He was conspicuous in action at the battles of Roanoke Island and New Bern. After the Battle of Roanoke Island, the Union renamed the Confederate Fort Bartow as Fort Foster in his honor. The US Army dismantled the three forts on the island in late 1865 after the end of the war.