"You need a surface (not contours) to calculate this in ArcGIS. The
tool is called Add Surface Information, and for polylines it will
return the 3d length (surface length) of the line. If you do not have
the DEM originally used to derive the contours, you can interpolate a
new DEM from the contours using the Topo to Raster tool. Otherwise,
just use the original DEM the contours came from." ref
See this video. https://www.youtube.com/watch?v=vPk93VfydB4 The gist of it is that you need to pass the line to a geoprocessing tool from the 3D Analyst Toolbox called "Add Surface Information"
If you are looking for a direct way to measure distance over topo lines, you are really asking about "Slope Distance" or "Ground Distance", at which point you have to intersect the lines, get the start and end elevation, the length of the segment, and apply some simple Pythagorean math to accomplish this. Visit this page for details on the math part.
Either of these options can be done programmatically using Python or in either desktop clients (ArcMap, Pro).