Foster was acting as chief engineer of the fortifications of Charleston Harbor at the outbreak of the war. After the bombardment of Fort Sumter, he was promoted to brigadier general of volunteers. He was involved in the North Carolina expedition of 1862 and assigned to command the Department of North Carolina. He participated in the capture of New Bern, NC, and in the bombardment of Fort Macon , GA. In July 1863 he was brevetted a major general of volunteers. In his next appointment, Foster commanded the department of Ohio but was forced to relinquish command when he fell from his horse and sustained injuries. Returning to service, he commanded the Department of the South in the last year of the war. After the war, Foster was put in command of the department of Florida.