Easily! Flies have tiny claws at the ends of their feet that grip the rough spots on ceilings, windows, or walls. Also, their feet have hairy pads covered with a sticky substance that helps them cling to any surface. It’s a little like walking with chewing gum on the bottom of your shoes.
Between the claws and the sticky stuff, flies can walk anywhere they want!