my $exp = Expect->spawn("sftp","username@host") or fatalmsg("$sender Cannot spawn sftp command"); $exp->expect($timeout, ["Password Authentication"], ["Are you sure you want to continue connecting", sub {my $self = shift; $self->send("yes\n");}] ); $exp->expect($timeout, ["password:"]); $exp->send('xxxxx'); $exp->expect($timeout, ["sftp>"]); my $cmd = "rename path/Long_Filename new_path/Long_Filename"; $exp->send("$cmd\n"); $exp->expect($timeout, ["sftp>"]);