Common SSH clients read the password from the TTY, not from STDIN. Try using a certificate to authenticate yourself or check (man ssh or ssh --help) if your SSH client could be forced to read the password from STDIN.
Note that your program contains clear-text password and due to this it is a high security risk.