In Perl:
# untested:
my ($host, $user, $pwd, $dir) = (...);
use Net::SFTP::Foreign;
use Fcntl ':mode';
my $deadline = time - 24 * 60 * 60;
my $sftp = Net::SFTP::Foreign->new($host, user => $user, password => $pwd);
$sftp->setcwd($dir);
my $files = $sftp->ls('.',
# callback function "wanted" is passed a reference to hash with 3 keys for each file:
# keys: filename, longname (like ls -l) and "a", a Net::SFTP::Foreign::Attributes object containing atime, mtime, permissions and size of file.
# if true is returned, then the file is passed to the returned Array.
# a similar function "no_wanted" also exists with the opposite effect.
wanted => sub {
my $attr = $_[1]->{a};
return $attr->mtime < $deadline and
S_ISREG($attr->perm);
} ) or die "Unable to retrieve file list";
for my $file (@$files) {
$sftp->remove($file->{filename})
or warn "Unable to remove '$file->{filename}'\n";
}