Moved the ssh operation outside the loop.

It seems that ssh inside the loop caused confusion, most likely because of
the I/O redirections.