Hydrodynamic surface interactions enable Escherichia coli to seek efficient routes to swim upstream.