# initialize an Expect object: my $conn = Expect->new; $conn->raw_pty(1); # spawn a new SSH process: $conn->spawn('/usr/bin/ssh', -l => $user, $host, -s => 'sftp') or die $errstr; # wait for the password prompt: $conn->expect($timeout, "Password:") or die "Password not requested as expected"; $conn->send("$passwd\n"); # SSH echoes the "\n" after the password, remove it from the stream: $conn->expect($timeout, "\n");