Judge Farish refused a request for continued name suppression and told McGlashan he was "in denial" by suggesting a different scenario to the police summary of facts after he pleaded guilty.
The horrific incident last December sent shock waves through the small North Canterbury town where it happened.
McGlashan, a fuel delivery truck driver whose job took him throughout North Canterbury, met the child by chance when he was parked outside the local store.
He struck up a conversation with her after she showed interest in his truck. She refused a ride in the truck and scooted off home.
He followed her in his truck and went inside the girl's house despite knowing that the girl's grandparents were absent and she was alone.
Police said the victim showed him around the house including her upstairs bedroom.
Once inside the bedroom, McGlashan pushed her onto the bed, knelt on the floor in front of her, pulled her pants down and attempted oral sex.
The horrified girl said no and stood up crying. McGlashan tried to calm her, but she told him to go away and never come to her house again.
As soon as McGlashan left, she ran back to the store for help. A witness described the girl as looking "petrified".
In court on Wednesday, Judge Farish told McGlashan both offences were "very serious".
Police found more than 2000 objectionable images on McGlashan's laptop computer, 168 of them portraying very young girls.
Judge Farish said McGlashan told the girl she was very beautiful and that "beautiful little girls could get raped". He then explained what that meant.
She said the incident was "opportunistic" and involved an attempt to act out his sexual fantasy.
"Once you were inside the house and started a sexualised conversation with her, then in my view that's when the fantasy you have suppressed started to take over."
The girl's grandfather told The Star he was satisfied with McGlashan's sentence.
"It's adequate. It's not too low. Hopefully he'll get some help, God knows he needs it."
The grandfather said he was pleased McGlashan's name and image were being published.
"It's very important that local people know who he is," he said. "People used to think he was a nice fellow. He's been operating in farming areas throughout North Canterbury."
The grandfather said he and his wife told everybody in the district what happened and kept the school informed.
He was "very proud" of the way his grand-daughter reacted to McGlashan's attack.
"She did everything right," he said.
"She made a noise, told him to go away, ran out screaming and went to get help. We're very proud of her."
He said he and his wife told her that McGlashan had been sent to jail.
"There were big smiles all around and a big hug."
He said the usually outgoing little girl became nervous and clingy immediately after the attack, but was becoming her old self.