#!/usr/bin/perl use strict; use warnings; use Net::SFTP::Foreign; use Fcntl ':mode'; my $host = 'localhost'; my $dir = shift @ARGV; my $sftp = Net::SFTP::Foreign->new($host); $sftp->find($dir, ordered => 1, wanted => sub { my (undef, $entry) = @_; if (S_ISREG($entry->{a}->perm)) { my $fn = $entry->{filename}; $sftp->rename("$fn", "$fn.bak"); } 0; }, );