The third-round victory left the Swiss star relieved he was still around.
"This win today was perfect," Federer said. "It gives me another opportunity to play another match. I'm further into the tournament, which normally makes me play better."
Second-ranked Andy Murray was much sharper under the conditions, beating Radek Stepanek of the Czech Republic 6-4, 6-1. Murray kept the ball in play, had only 14 unforced errors and was broken only one time - impressive numbers under the conditions.
"I saw a little bit of Federer's match before I was going on. You know you can't play to the lines," Murray said. "You're going to miss-hit some shots. It's just important not to get too frustrated."
No. 4 Novak Djokovic beat Jeremy Chardy of France 7-5, 6-3. Third-ranked Rafael Nadal had an evening match.
Unseeded Lleyton Hewitt, a two-time runner-up, edged Sam Querrey of the United States 6-1, 2-6, 6-3 to line up Federer next.
Following his post-match interview on the court, Federer swatted some souvenir balls into the stands - well, all but one that flew out of the stadium, demonstrating what the players had been up against. Every mistake was magnified.
"Just play smart," Federer said. "If you play dumb in the wind, that can backfire big time."
Federer took time off after his Wimbledon victory - his record 15th Grand Slam title - to become the father of twin girls. His difficulties on Thursday had little to do with the layoff and everything to do with the wind, which played havoc with shots.
Federer usually likes to play in the wind but had an uncharacteristic 35 unforced errors against Ferrer, who was winless in nine career matches against the world No. 1 and has won only two sets in those matches.
Federer made 16 unforced errors in the opening set, unable to get the ball to land where he wanted. The swirling wind tousled players' hair, rippled their shirts and made the turned-off circular fans behind the players' chairs whirl as if they were drawing electricity.
The Spaniard seemed to draw energy off Federer's difficulties. When Ferrer broke to go up 3-2 in the third set, he had his chance.
Immediately, he blew it.
Federer broke him right back to tie it at 3. Upset over the wasted opportunity to take control, Ferrer angrily swatted a ball into the stands and dropped his racket. He sensed he might not get another opening.
He didn't.
Federer broke him to go up 5-4 with a move that showed he had gotten a feel for the wind. He chipped a backhand that drew Ferrer to the net, then deftly lobbed a backhand over his head - the wind-pushed ball landed perfectly inside the baseline.
"I think at the beginning, maybe my footwork was just a touch off," Federer said. "After that, I think I got it together and started to play better and better. In the end, when it goes your way, all of a sudden you can actually use the wind to your advantage in a big way. That's what I hoped to do the whole match today, but it's not so easy sometimes."
Toffees show Lescott loveFederer, Nadal both out of Rogers Cup