We report on the emergence of spontaneously forming migrating bands of E. coli bacteria inside a microchannel containing microstructured ratchets. We show that a collection of bacteria is able to migrate against the funnel-shaped barriers by creating and maintaining a chemoattractant gradient. A transition between pure rectification and chemotaxis-driven collective motion is predicted from theoretical models, and is observed experimentally as the initial inoculation density is varied.