Connected graphs without long paths

We determine the maximum number of edges in a connected graph with n vertices if it contains no path with k+1 vertices. We also determine the extremal graphs.