A retired music teacher who taught for almost 40 years in Long Island school districts was sentenced Monday to 32 months in prison on a child pornography charge in federal court in Central Islip.

David Kopstein, 70, of Franklin Square also was sentenced to 5 years of supervised release by U.S. District Judge Arthur Spatt, ordered to undergo mental health counseling and fined $5,000.

Kopstein, who had taught for 38 years in the West Hempstead and Port Washington districts, was arrested in July 2015 on charges of possession and transportation of child pornography. Kopstein was not accused of abusing any students.

An expert trumpet player, Kopstein played that instrument in a number of bands on Long Island and was part of a traditional brass band that played for the Ken Burns Civil War series on public television.

In addition, Kopstein donated his time to sound taps at military funerals.

In a pre-sentencing memorandum, Kopstein wrote to Judge Spatt: “I now suffer shame, regret, and self-contempt — not only because of being arrested and publicly humiliated, but because in my own mind, I deserve it. My selfishness has adversely affected my family and my actions will haunt me for the rest of my life.”

advertisement | advertise on newsday

Kopstein’s arrest came six years after a son, Scott Kopstein, also of Franklin Square, was arrested on child pornography charges. Scott Kopstein eventually served 5 years in prison.

Eastern District prosecutor Allen Bode said in court papers that Kopstein “continued to look at child pornography sites a couple of years after his son had been arrested . . . he did not know why he started but he knew it was wrong and illegal.”

Kopstein’s wife, Ilene, a psychologist, said in a letter to the judge that: “I believe that my husband retained illegal images on his computer as a result of an unconscious wish to be punished for not being more strict with Scott.”

As part of a plea deal, Kopstein pleaded guilty to a single count of possession of child pornography.

He faced from 37 to 46 months in prison under suggested sentencing guidelines.

Kopstein’s attorney, Jeffrey Pittell of Bayside, asked that his client be sentenced to time served, the 18 months he has been imprisoned since his arrest.

In issuing the sentence, below the guidelines, Spatt said he was balancing Kopstein’s career and service with the seriousness of the crime. Given that Kopstein already has been jailed for 18 months, he will have to serve at most 14 more months.

“We were hoping for time served, but we appreciate that the judge gave fair consideration for this case and imposed a sentence that was below the guidelines,” defense attorney Pittell said afterward.

Bode declined to comment.