In a scene taken straight out of an American Wild West movie, masked men robbed a freight train in southern France after blocking the railway tracks with shopping carts and metal beams.

The daring attack on the northern outskirts of the southern French city of Marseille saw a passenger train hurtling into the blockade forcing it, and a cargo locomotive behind it, to stop.

"Attacks on trains aren't new, but it is a pretty rare phenomenon," David-Olivier Reverdy, a police union official in the area said.

"It's worthy of stagecoach attacks in the Wild West," he said.

About 20 bandits looted several carriages and then vanished into the night. It was unclear what was taken.

Nobody was injured in the attack, but Reverdy said the thieves had put people's lives in danger.

The railway union said in a statement that while such attacks were rare, the robbery was a sign that the railway authority was not investing enough in the security of its sites. (Reuters)