Warning! If you open a ssh connection and execute an external program opening another ssh connection it may result in very strange behavior.
I used an sftp connection to get a file list and used "exec" to download the files afterwards with an external sftp. lftp downloaded zeros with no comment, psftp exits with error code 11 most of the time, but sometimes it works - probably depending on how quickly php collects garbage and closes the unused connection first.
As there is no function to close a connection, you need to be sure to destroy all references (unset) to close it.