#!/usr/bin/perl
# Load the Net::FTP package
use Net::FTP;
$host = 'http://refactormycode.com/';
$path = '/httpdocs/rep/';
$ftp = Net::FTP->new($host, Timeout => 60, Passive => 1)
or die "Cannot contact $host : $!";
$ftp->login('****', '*****')
or die "Can't login ( $host) : " . $ftp->message;
print "Login eseguito\n";
$ftp->cwd($path)
or die "Can't change directory ($oath):" . $ftp->message;
print "Switching to dir $path\n";
#Take filelist and sort by last modified field
@filelist = $ftp->dir();
@filelist = sort {(stat($a))[9] >= (stat($b))[9]} @filelist;
#Take the first element
$file = $filelist[0];
#Extract filename form $file
$_ = $file;
m/^(.*)(\d+:\d+\s)(.*)$/;
$filename = $3;
print "Download " . $filename . "...";
$ftp->get($filename)
or die "$!";
print "done\n";
#I want to untar in backup directory
print "Create folder...";
system('mkdir backup');
#system("mv $filename backup/");
print "done\n";
print "unpacking....";
$command = "tar xvf " . $filename . " -C backup/";
system($command);
print "done\n";
print "Delete old file...";
$command = "rm " . $filename;
system($command);
print "done\n";
Refactorings
No refactoring yet !
bruce
August 10, 2010, August 10, 2010 09:02, permalink
hi what compilator do you use or what program?
thanks
I code this script for need, it's about 2 years I don't code in Perl...