#!/usr/bin/perl use Net::FTP; use Archive::Zip; use IO::File; use File::Spec; use File::Copy; print "Retrieving file from logs.com...\n"; $loginip = '1.2.3.4'; $loginid = 'loginid'; $loginpaswd = 'pswd'; ( $sec, $min, $hour, $mday, $mon, $year ) = ( localtime(time) )[ 0, 1, 2, 3, 4, 5 ]; $time_stamp = "_" . ( 1900 + $year ) . "_" . ( $mon + 1 ) . "_" . ($ +mday) . "_" . $hour . "_" . $min . "_" . $sec; printf "time stamp = $time_stamp\n"; unless ( -d "SEC5TFLogs" ) { mkdir("SEC5TFLogs"); } if ( -d "SEC5TFLogs" ) { chdir("SEC5TFLogs"); } $ftp = Net::FTP->new( ($loginip), Debug => 0 ) or die "Cannot connect to logs.com: $@ \n"; $ftp->login( $loginid, $loginpaswd ) or die "Cannot login ", $ftp->message; $source_dir = "/a/b/c/d/"; print "Source Dir is $source_dir\n"; my @dir= $ftp->ls($source_dir); foreach $trident (@dir) { print "The tridents are $trident\n"; $ftp->cwd($trident) or die "Cannot change working directory ", $ftp-> +message; $ftp->binary || die "Unable to set mode to binary. ", $ftp->message; my $destinationDirectory = '\\\\1.15.1.40\E$\Sec5Logs'; my($vol,$dir,$tridentfile) = File::Spec->splitpath($trident); print "$tridentfile\n"; mkdir "$destinationDirectory/$tridentfile"; @list = $ftp->ls(); my ( $var1, $var2, $var3, $var4, $var5 ) = split( / /, scalar( localti +me( time - 86400 ) ) ); my $dateformat = "$var2$var3$var5"; print "Dateformat is $dateformat\n"; #printf "list = \n"; #print @list; foreach $file (@list) { if ( $file =~ /Trident..*$dateformat..*\.zip/i ) { $ftp->get($file) or die "get failed ", $ftp->message; printf "ftp done\n"; printf "Moving the file to 1.15.1.40 machine\n"; move("$file","$destinationDirectory/$tridentfile/$file"); printf "Moving of the file $file is done\n"; } print "The files are downloaded successfully\n"; closedir DIR; } $ftp->quit;
In reply to FTP to local machine by nt2282
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |