#!/usr/bin/perl -w use strict; use warnings; use Net::SFTP::Foreign; use POSIX qw(strftime); my $datestring =strftime "%d-%m-%Y", localtime; my $host="sftp.brusselsairlines.com"; my $username="dlex"; my $local="/mnt/datalex"; my $file="BookingReport_Daily_$datestring.xls"; my $sftp = Net::SFTP::Foreign->new($host, user=> $username, stderr_discard => 1 ); $sftp->die_on_error("unable to establish SFTP Connection"); my $ok = 0; my $failed = 0; if ( -e "$local/$file"){ print "File \"$file\" has already been Downloaded to ==> \"$local\"\n" } else { if ($sftp->get("$file", "$local/$file")) { print "File \"$file\" downloaded to ==> \"$local\"\n"; $sftp->remove($file); $ok++; } else { print "Unable to download file \"$file\" : " . $sftp->error . "\n"; $failed++; } } print "$ok files have been downloaded, $failed files failed!\n\n"; $sftp->disconnect();