It would be helpful to know what you're trying to connect to. Also, you may want to look into checking for errors in your code. You don't seem to have anything in place for validating that you've successfully connected... I would start there. Change the username and password to something that should fail and see if you see an error.
I've tried a number of different SSH libraries, for perl, python, .NET, you name it for automating changes to networking devices. The most common thing that I came across was that some connecting would work, logins worked fine, but attempting to pass a command would either time out or fail. I looked into using different versions of SSH but that didn't seem to make a difference. Some devices seem to require sending either "\n" or "\l\r" prior to accepting commands. I could get things to work using a linux box as a test server, but connecting to a switch or WAP would not allow me to pass commands.
In the end, I gave up and cobbled something together using AutoIT or tried using telnet - which is a bad idea in most environments, but perl, python, and .NET work wonderfully with telnet connections. PHP does as well.
I wasn't even able to pass commands in using SSH scripts (flat text files containing commands to be passed on successful login) that are supported by a number of applications ( putty, I think, and OpenSSH ).