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>"]); #### sub print (@) { my ($self, @args) = @_; return if not defined $self->fileno(); # skip if closed if (${*$self}{exp_Exp_Internal}) { my $args = _make_readable(join('', @args)); cluck "Sending '$args' to ${*$self}{exp_Pty_Handle}\r\n"; } foreach my $arg (@args) { while (length($arg) > 80) { $self->SUPER::print(substr($arg, 0, 80)); $arg = substr($arg, 80); } $self->SUPER::print($arg); } }