#!/usr/bin/perl use Net::SFTP; use IO::Uncompress::Gunzip qw(gunzip $GunzipError); use Date::Simple qw(d8); use DBI; use DBIx::Dump; use Time::Piece; use Time::Seconds 'ONE_DAY'; my $host = "10.x.x.x"; my $user = "xxx"; my $password = "xxx"; my $basedir = "locations"; my$reportfldr = "reports"; my $reportdr ="Reports_On_Request"; my $filename = 'List1.txt'; $date = $ARGV[0]; # date is your first argument{ FORMAT (20161125)}#### uncomment this line and enter date while running script if #you want to manually fetch report and commnet below block #autodate # my $out = qx(net time); #toget current date # my @sachin = split/\s+/,$out; #toget current date autodate # print "$sachin[5] \n"; #toget current date autodate # my @datesys = split/-/,$sachin[5]; #toget current date autodate # my $dt_column = join ("",$datesys[2],$datesys[1],$datesys[0]); #toget current date autodate # $date =$dt_column; #toget current date autodate # my $yesterday= (localtime() -ONE_DAY)->ymd(''); #autodate # print "$yesterday \n"; #autodate # $date = $yesterday; #autodate #Starting of Main Program # my $d = d8($date); my $error_log=$d-> format ('%d/%b/%Y'); #my $brchid="b00330"; ####brchid it is reading from branchList file ##### open (STDERR,">",$error_log) ; ############Fetching report from LHO Server######################################## open(my $fh, '<:encoding(UTF-8)', $filename)or die "Could not open file '$filename' $!"; while ( my $line = <$fh>) { chomp $line; my @splitline=split/[|]/,$line; my $brchid = $splitline[0]; my $region = $splitline[1]; my $netwrk = $splitline[2]; my $mod = $splitline[3]; my $rg = $splitline[4]; my $branchname = $splitline[5]; print "Starting $branchname\t"; $brnchid = substr $brchid,1 ; print "$brnchid upload \n"; system "mkdir $brchid"; chdir($brchid); system "mkdir $date"; chdir ($date); my $dir = join"/",$basedir,$brchid,$reportfldr,$date,$reportdr; print "$dir"; print " FTP is ongoing in main file \n"; my %args =( user =>'lho',password=>'lho',port=>22,debug=>'true'); my $f = Net::SFTP->new($host,%args); $f->ls($dir,sub {print $_[0]->{filename},"\n"}); my $file = join "/",$dir,"Status_Report_For_BGL_gend7058.txt.gz"; print "$file, i m sachin \n"; $f->get($file); #$f->exit;