Recent experiments proposed to use confined bacteria in order to generate flows near surfaces. We develop a mathematical and a computational model of this fluid transport using a linear superposition of fundamental flow singularities. The rotation of a helical bacterial flagellum induces both a force and a torque on the surrounding fluid, both of which lead to a net flow along the surface. The combined flow is in general directed at an angle to the axis of the flagellar filament. The optimal pumping is thus achieved when bacteria are tilted with respect to the direction in which one wants to move the fluid, in good agreement with experimental results. We further investigate the optimal helical shapes to be used as micropumps near surfaces and show that bacterial flagella are nearly optimal, a result which could be relevant to the expansion of bacterial swarms.