Since you state that when you manually ssh you are not asked for a username/password, it sounds as if you are logging in with the same username as on the local machine with a public key pair. In that case, in place of the login() call you may do something like this:
# $wait_time previously defined, in seconds
# $password previously defined
if ( ! $ssh->run_ssh() ) {
if ( $ssh->waitfor( "ontinue connecting", $wait_time ) ) {
$ssh->send("yes");
}
if ( $ssh->waitfor( "ssword", $wait_time ) ) {
$ssh->send( $password );
}
if ( $ssh->waitfor( "ast login", $wait_time ) ) {
# logged in
}
else {
# unexpected error
return undef;
}
}
# connected, continue on your way
Hope that helps.
Update: 2015-10-07
Changed variable name to make snippet more readable.