You can access the column names of a PGFplots table through the macro \pgfplotstablegetcolumnnamebyindex{<index>}\of{<table macro>}\to{<macro>}. You can use this while looping through the columns of a table using \pgfplotsinvokeforeach{<list>}{<commands>} to add the column names as legend entries.
I've written a \plotfile macro that takes a filename as argument and then plots all columns starting from the second column against the first column:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{filecontents}{testdata.dat}
Time Distance Velocity Something
0 0 1 0.2
1 1 1 0.3
1.999 1.999 1 0.4
2 2 0 0.4
3 2 0 0.5
\end{filecontents}
\newcommand{\plotfile}[1]{
\pgfplotstableread{testdata.dat}{\table}
\pgfplotstablegetcolsof{testdata.dat}
\pgfmathtruncatemacro\numberofcols{\pgfplotsretval-1}
\pgfplotsinvokeforeach{1,...,\numberofcols}{
\pgfplotstablegetcolumnnamebyindex{##1}\of{\table}\to{\colname}
\addplot table [y index=##1] {testdata.dat};
\addlegendentryexpanded{\colname}
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[legend pos=north west]
\plotfile{testdata.dat}
\end{axis}
\end{tikzpicture}
\end{document}
