Hi Monks,

I wrote a script for backup files from a server to a pc regularly. But it seems not work. Below is the code:
#!/usr/bin/perl use strict; use warnings; use Win32::DriveInfo; use File::Path; use Net::FTP; ## define variables # my %parameters; my $remote_server ; my $username ; my $password ; my $backup_dir ; my $backup_file_numbers ; my $driver_freespace ; my $remote_backup_dir ; my $remote_file ; my $file_name; my $new_directory; # Read parameters from CFG ## sub read_par { open (STDERR, ">>backup_err.log") or die "can't redirect STDERR $!\n"; print STDERR "Backup begin at: ",scalar localtime,"\n\n"; open (CFG,"<auto_backup.ini") or die "Can't open config file $!\n"; while (<CFG>) { chomp; s/#.*//; s/^\s+//; s/\s+$//; next unless length; my ($var, $value) = split(/\s*?=\s*?/, $_, 2); $parameters{$var} = $value; } close CFG; $remote_server = $parameters{'remote_server'} || "192.168.0.1"; $username = $parameters{'username'} || "dgc2000"; $password = $parameters{'password'} || "Dgc2000"; $backup_dir = $parameters{'backup_dir'} || 'D:\backup'; $backup_file_numbers = $parameters{'backup_file_numbers'} || '20'; $driver_freespace = $parameters{'driver_freespace'} || '5'; $remote_backup_dir = $parameters{'remote_backup_dir'} || "/usr/backup" +; $remote_file = $parameters{'remote_file'} || "dgc2000_backup.tar"; } #check driver space # sub check_space{ my $freebytes = Win32::DriveInfo::DriveSpace('d'); die scalar localtime,": Backup will be forcibly stopped due to the ins +ufficent system space, please check driver and set it free. \n\n" if +$freebytes < $driver_freespace; } ## check directory and create new. # sub check_dir{ opendir(DIR, $backup_dir) or die "can't opendir $backup_dir:$!"; my @dots = sort {[stat($a)]->[9] <=> [stat($b)]->[9]} grep {!/\.$/ && +-d} map {join '\\', $backup_dir,$_} readdir(DIR); if (@dots > 1) { map {rmtree($_)} [@dots[1..$#dots]]; } } # create new directory sub create_dir{ my $localtime = scalar localtime; $localtime =~ s/:|\s/_/g; $new_directory = join ('\\',$backup_dir,$localtime); mkpath($new_directory) or die "error!!\n $!"; } # create ftp connection and fetch file. # sub fetch_file { my $ftp = Net::FTP->new($remote_server) or die "Cannot connect to $rem +ote_server: $@"; $ftp->login($username, $password) or die "Cannot login",$ftp->message; print $remote_backup_dir; $ftp->cwd($remote_backup_dir) or die "Cannot change working directory +", $ftp->message; $ftp->binary; $ftp->get($remote_file, $remote_file, $new_directory) or die "get fail +ed", $ftp->message; $ftp->delete($remote_file) or die "Can't delete", $ftp->message; $ftp->quit; die "backup end successfully at: ",scalar localtime,"\n\n"; } sub init { read_par(); check_space(); check_dir(); } sub backup { create_dir(); fetch_file(); } init(); backup(); __output__ Backup begin at: Tue Sep 4 12:33:04 2007 get failed'REST D:\backup\Tue_Sep__4_12_33_04_2007': command not under +stood.
It seems be lead by windows path. But I can't confirm it. Any body could point out a right way to solve this problem? And, after passing by this issue, I'd also like to learn other backup perl snippets to improve my skills.

Thanks in advance!

I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

In reply to Net::FTP can't fetch file to local directory? by xiaoyafeng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.