Hi,
I can't see how your code would work, I think you've missed couple of somethings.
As I saw on many websites, you need to use the function "ssh2_exec" instead of "exec" and you need to run the commands one by one.
Also, in your case you can't use the command:
$progress=mysql_affected_rows(); // line 38
because you're not managing the mysql connection by php.
For more info about ssh connection try this link and search for "Great! PHP supports SSH - time to code" to skip server configurations.