In 1862 Townsend was Acting Lieutenant of the USS Miami (1861) under the command of Abram Davis Harrell. The Miami was a side-wheel, double-ender gunboat with a crew of 134 and armament of one 80 pounder Parrott rifle one 9 inch smoothbore, and four 24 pounder cannon. The ship participated under Admiral David Farragut as part of the Mortar Flotilla in neutralizing Confederate forts below New Orleans. Eliminating the forts permitted the Union ships to move upriver and eventually take New Orleans. Townsend became Commander of the Miami by October of that year
In 1863, he was promoted to Commander and given command of the USS Essex (1856) under Admiral David D. Porter’s Mississippi Squadron. The USS Essex was a 1000 ton ironclad river gunboat of the United States Army and later United States Navy during the American Civil War. It was named for Essex County, Massachusetts. USS Essex was originally constructed in 1856 at New Albany, Indiana as a steam powered ferry named New Era. She had a crew of 134, armament consisting of 1 x 32-pounder; 3 x 11-inch Dahlgren smooth bores;1 x 10-inch Dahlgren smoothbore;1 x 12-pounder howitzer, and armor consisting of 1 ¾" forward casemate, ¾" sides.
Under Townsend’s command the Essex participated in the Siege of Port Hudson which occurred from May 21 to July 9, 1863, when Union Army troops assaulted and then captured the Mississippi River town of Port Hudson, Louisiana. Along with the USS Mortilla, the Essex bombarded the area daily and helped bring about the surrender of the city. The Union’s success in this battle gave Northern forces effective control of the Mississippi River and effectively cut the states of Arkansas and Texas off from the rest of the confederacy.
On 9 July she engaged the enemy at Donaldsonville and although damaged in the battle, carried out her patrol duty at this point through 6 March 1864 when she sailed with the fleet into the mouth of the Red River and assisted in the capture of Fort de Russy on 15 and 16 March.
Townsend relinquished command of the Essex on 3 November 1864 to Commander Bryson.
After relinquishing command of the Essex, Townsend was given command of the USS Wachusett. The Wachusett was a wooden steam frigate with a detachable propeller, carrying nine guns and a complement of 170 men. She was a large (1,032-ton) steam sloop-of-war that served the United States Navy in the American Civil War. She was outfitted as a gunboat and used by the Navy as part of the Union blockade of the Confederate States of America. On 17 February 1865 The ship was given orders to proceed to the East India (China) station by way of the Cape of Good Hope. There, she joined USS Wyoming and USS Iroquois in an effort to track down the Confederate commerce raider CSS Shenandoah.
While in China the ship was engaged in efforts to track down outlaws and pirates who were harming American interests. In mid-August the ship sailed up the Yangtze River in this mission. The heat was reportedly 107 degrees Fahrenheit in the shade and the ship made difficult passage up the river. A number of cases of heat stroke, some of them fatal occurred. At 1:45 am on 15 August, 1866, Robert Townsend died of heat stroke. The executive officer John Woodward (Jack) Philip, (later Admiral) assumed command of the Wachusett and sailed it downriver with the goal of making it to Japan for the health of the crew. That evening the ship anchored by the consulate in Shanghai and held a funeral for their commander.