Harold T. Martin III, a former contractor for the National Security Agency, was arrested by the FBI in August after authorities say he admitted to having taken government secrets. His attorney said Martin did not intend to betray his country. (Patrick Semansky/Associated Press)

A former National Security Agency contractor accused of stealing a huge cache of classified documents pleaded not guilty Tuesday to spying charges in federal court in Baltimore.

Harold T. Martin III was indicted last week by a federal grand jury, accused of violating the Espionage Act by carrying out what officials say is the largest theft of classified information in U.S. history.

Martin, 52, was arrested in August at his home in Anne Arundel County, Md., where law enforcement officials recovered dozens of computers, digital storage devices and thousands of hard-copy documents that filled six bankers’ boxes. Prosecutors say Martin hid classified and top-secret information in the trunk of his car, his home office and an unlocked outdoor shed.

In a brief court appearance Tuesday, Martin told Magistrate Judge A. David Copperthite that he understood the significance of the indictment charging him with taking and retaining a huge amount of classified material. The charges carry a maximum prison sentence of 10 years for each of 20 criminal counts.

If the case goes to trial, prosecutors said they expect it would last three to four weeks.

Harold T. Martin III (Anne Arundel County Police)

Martin, who has been held in a detention facility since his arrest and was dressed Tuesday in a black-and-white striped uniform, is not accused of trying to disseminate or publish the information he is accused of stealing.

“He’s not Edward Snowden,” Martin’s attorney James Wyda said during an earlier detention hearing, referring to the former intelligence contractor who gave classified material on U.S. surveillance programs to the media.

“He’s not someone who, due to political ideas or philosophical ideas or moral principles, thinks he knows better than everybody else and, hence, is compelled to release government secrets,” Wyda said.

Martin’s attorneys have previously said he took documents home not to harm the United States but to get better at his job. Martin has a compulsive hoarding habit, his attorneys said, and was taking medication for attention-deficit disorder that was a “trigger” for hoarding.

Martin first received security clearance on active duty in the Navy. He went on to work for seven private companies at various agencies within the intelligence community, including the CIA, the U.S. Cyber Command and the Office of the Director of National Intelligence.

He was a “trusted insider,” prosecutors said, working at the NSA from 2012 to 2015, where he was an employee of the intelligence contractor Booz Allen Hamilton. Martin was for some time in the NSA’s elite hacker unit, Tailored Access Operations, which makes and deploys software used to penetrate foreign targets’ computer networks for foreign espionage purposes.

At the time of his arrest, Martin was enrolled in a doctorate program in information security management and doing research for his dissertation. He has an extensive background in computer security, including in the areas of encryption and secure communications.

Many of the documents Martin is accused of stealing were marked top-secret and contained highly classified information, including the names of intelligence officers who operate undercover outside the United States, according to the 12-page indictment. Among other secret documents, authorities found an NSA anti-terrorism document related to “extremely sensitive U.S. planning and operations regarding global terrorists,” according to the indictment.

Prosecutors described the theft in court filings as “breathtaking in its longevity and scale.”

“Harold Martin flagrantly abused the trust placed in him by the government by stealing documents containing highly classified information,” Maryland U.S. Attorney Rod J. Rosenstein said in a statement after the indictment was returned last week.

Ellen Nakashima contributed to this report.