Let $k\in\text{ran} T$. Then $k=Tf$ for some $f$, i.e. $k=\lambda g$, where $\lambda=\langle f,h\rangle$. So every element in $\text{ran}\,T$ is a scalar multiple of $g$. Thus, $\text{ran}\,T$ has a basis consisting of $\{g\}$, i.e. it has dimension $1$.
Now assume that $T$ is finite rank. Let $g_1',\ldots,g_n'$ be an orthonormal basis of $\text{ran}\,T$. Then, for every $f\in H$, $Tf=\sum_j\lambda_j(f)\,g_j'$, with the coefficients $\lambda_1(f),\ldots,\lambda_n(f)$ uniquely determined for for each $f$. So, for each $j$, the map $f\mapsto\lambda_j(f)$ is a linear functional on $H$. Note that $ |\lambda_j(g)|\leq\left(\sum_{k=1}^n|\lambda_k(f)|^2\right)^{1/2}=\|Tf\|\leq\|T\|\,\|f\|, $ so every $\lambda_j$ is a bounded functional. By the Riesz Representation Theorem, there exist vectors $e_1',\ldots,e_n'$ such that $\lambda_j(f)=\langle f,e_j'\rangle$. So $ Tf=\sum_{j=1}^n\langle f,e_j'\rangle\,g_j',\ \ \ \ \ f\in H. $
Now, using Gram-Schmidt, there exist $e_1,\ldots,e_n$, orthonormal, such that $ e_k'=\sum_{j=1}^k\lambda_{kj}e_j $ for coefficients $\{\lambda_{kj}\}_{k=1,\ldots,n; j=1,\ldots,k}$ (note that these are not the equalities from Gram-Schmidt, but rather the inverse form, where we express the old vectors in terms of the new orthonormal ones). Then $ Tf=\sum_{k=1}^n\langle f,e_k'\rangle\,g_k'=\sum_{k=1}^n\langle f,\sum_{j=1}^k\lambda_{kj}e_j\rangle\,g_k'=\sum_{k=1}^n\sum_{j=1}^k\lambda_{kj}\langle f,e_j\rangle\,g_k'=\sum_{j=1}^n\langle f,e_j\rangle\,\left(\sum_{k=j}^n\lambda_{kj}g_k'\right). $ Letting $g_j=\sum_{k=j}^n\lambda_{kj}g_k'$, $j=1,\ldots,n$, we get the desired expression.