Icon Legend Indicates the start of a new string. Indicates a message in a thread. Number of arrows indicates message level within thread. If they are of the smaller varieties that are more commonly found on kitchen counters, they are probably feeding on food scraps near the surface of your composting mass. They will probably move elsewhere if you make sure all food scraps are mixed deep into a hot moist composting mass inside the pile.
Most flies prefer to lay eggs in meat but are happy with veggies too, especially fruit flies.
You can keep the maggots from maturing into pesky flies by altering their environment. Maggots and flies are just a momentary nuisance. However, if the material is allowed to finish aerobic composting to a nice, crumbly, humus-rich consistency, there will be very little chance of catching anything from it, and after it has been applied to the soil and resided there for a year, it will be thoroughly disinfected. I'm not sure how to get rid of them. It is a bit damp from recent rain, so I have turned it, but I don't want them to stay.