Paul Whelan's lawyer says he is a victim of a set up The attorney provided the first detailed account of Whelan's side of the story.

Moscow -- Paul Whelan, the former U.S. Marine arrested in Moscow on espionage charges, says he is the victim of a setup by Russia’s security services, the American's lawyer said on Thursday.

Whelan was detained in Moscow in late December by Russia’s domestic intelligence agency and accused of unspecified “spying activity.” On Thursday, Whelan appeared again in a Moscow court, which rejected his appeal to be released on bail.

Russia has not provided any details on the spying charges against Whelan, but his lawyer has previously said he is accused of receiving “state secrets” on a memory card given to him by a Russian acquaintance during his trip in December. The lawyer has said Whelan, though, had not known what he was receiving -- believing he was being given holiday photographs.

On Thursday, for the first time, Whelan's lawyer accused the Russian friend of taking part in a sting operation against Whelan intended to frame him.

“I believe that it was a joint provocation from the side of his acquaintance and Russia’s security services,” attorney Vladimir Zherebenkov told ABC News outside a courtroom where Whelan's appeal hearing was taking place.

The lawyer said that case materials showed investigators now also accuse Whelan of spying "in the interests of the U.S.", though he said that accusation seemed based largely on the fact Whelan had travelled to Russia on an American passport.

Whelan himself appeared in court on Thursday, brought into the hearing by a masked officer and held in a glass cage. Whelan was far more agitated than at earlier hearings and was clearly upset by his treatment by the court and by his detention at the jail where he is being held.

"This is a kangaroo court," Whelan told reporters, after the judge rejected his appeal.

Almost since the moment of his arrest, there has been speculation that Whelan could have been framed, with former U.S. officials suggesting the case resembled classic KGB setups. His family has insisted the charges against Whelan, a security director for the Michigan car parts supplier, BorgWarner, cannot be true and have recently accused Russia of taking him hostage for political reasons.

Whelan's family have expressed concern about Zherebenkov, who was appointed as Whelan's lawyer and has declined to explain how he came to be involved in the case.

On Thursday though Zherebenkov gave what he said was Whelan's account of what he said was a trap laid against him.

According to Zherebenkov, Whelan had known the Russian friend who set him up for several years and in May 2018 the two had spent a few days relaxing in the countryside outside Moscow in an area called Zagorsk. During the trip, the two barbecued and went to a sauna, Zherebenkov said.

When Whelan traveled again last December to Moscow, according to his family to attend a wedding, he asked the Russian friend to bring him photographs of the spring trip.

He invited the friend to bring the pictures to his hotel room in the upscale Metropol hotel, Instead, Zherebenkov said, the friend deliberately brought a memory card that contained the “state secrets”.

Zherebenkov said that about five minutes later, before Whelan had chance to see what was on the memory card, agents from Russia’s Federal Security Service (FSB) burst into the hotel room and arrested him.

“It’s clearly a provocation,” Zherebenkov said. “Paul claims that and the investigation for now cannot refute that. In the words of Paul, it is a fantasy of the FSB.”

Zherebenkov said the secrecy laws prohibited him from naming the Russian acquaintance, but he said that he had "connections to the security services." The lawyer said that the friend may have trapped Whelan in the hope of “advancing his career". Zherebenkov also claimed that the friend owed Whelan money and that having him jailed would be a way to avoid paying the debt.

In the words of Paul, it is a fantasy of the FSB.

In the courtroom Whelan told reporters he was not allowed to comment on the case, directing them to ask Zherebenkov but he indicated that he believed he was being treated unjustly.

Asked if he had been set up, Whelan replied “What do you think?” and gestured at his lawyer.

At the hearing he was generally composed but he became agitated when the judge began reading the ruling in Russian, loudly demanding that he be provided with a translator as required by law. Another Russian lawyer assisting Zherebenkov, Olga Karlova quickly came over and began translating for him.

Whelan is being held in Moscow's Lefortovo prison, a former KGB jail known for housing accused spies, political dissidents and high-profile suspects. Whelan's family and U.S. diplomats have expressed worries that he is being isolated there, deliberately prevented from communicating with his family or from choosing his own attorney.

Whelan's twin, David, on Thursday tweeted that his brother had been "entrapped by the FSB" and wrote it was "no surprise the Russian authorities continue his isolation, where he can't communicate freely with family, consular staff."

Whelan holds British, Canadian and Irish passports, in addition to his U.S. and all four countries have been seeking to provide consular access. Russian authorities though have already delayed access for British and U.S. diplomats. American diplomats have expressed particular concern that Whelan has not been permitted to sign a Privacy Act waiver, a standard form that would allow them to discuss the case with his family.

In the courtroom Whelan told reporters he was being prevented from speaking with anyone and that he was unable to see any news in the prison.

Speculation that Whelan could have been seized as a hostage emerged quickly after his arrest, with some former U.S. officials suggesting that he could have been taken as leverage in retaliation for the detention of Maria Butina, the Russian gun rights activist who pleaded guilty in the U.S. in December to acting as an illegal agent on behalf of Russia.

Officials in Britain and Canada have expressed fears that Russia may have taken him as a diplomatic pawn. U.S officials have called on Russia to provide details about the charges against him, but the State Department has so far made little response to the case. President Donald Trump in passing has said his administration is looking into the case but has made no formal comment on it.

The Kremlin has rejected the suggestion that Whelan's case is political and has denied that it is seeking any prisoner exchange.

Concern in Congress though has been growing. Last week, a group of U.S. senators, including the chairman of the House Foreign Affairs Committee, Eliot Engel demanded that Russia immediately release Whelan. In a statement, Engel wrote that Russia's treatment of Whelan violated international law.

U.S. embassy diplomats were due to visit Whelan again on Friday.