phathead22 has asked for the wisdom of the Perl Monks concerning the following question:

Oh great ones: I am backing up a data base to numerous areas; will need to use ftp (net::ftp?) and system calls (xcopy for NT/2000) to copy uncompressed files. So far, I have yet to get either ftp or system calls working properly. Any advice?

Replies are listed 'Best First'.
Re: PERL backup routine
by c-era (Curate) on Jan 16, 2001 at 21:17 UTC
    Active perl comes with Win32::Internet which has a ftp client. You can also use ppm to get libnet which has net::ftp. To do the file copy I would suggest the builtin module File::Copy.

    An example of Win32::Internet:

    use Win32::Internet; my $host = 'localhost'; my $user_name = 'user'; my $pass = 'password'; my $file = 'somefile'; my $inet = new Win32::Internet (); $inet->FTP($FTP, $host, $user_name, $pass) || die $!; $FTP->Put ($file) || die $!;
    An example of Net::FTP:
    use Net::FTP; my $host = 'localhost'; my $user_name = 'user'; my $pass = 'password'; my $file = 'somefile'; my $FTP = Net::FTP->new($host) or die $!; $FTP->login($user_name,$pass) || die $!; $FTP->put($file) || die $!;
    And an example of File::Copy:
    use File::Copy; my $source_file = 'somefile'; my $dest_file = 'somefile'; copy ($source_file, $dest_file) || die $!;
      When using Net:FTP as per your example, I get the following error (in debug mode or from the script):

      #" Can't locate object method "requires_firewall" via package "Net::Config" at C:/Perl/lib/net/FTP.pm line 52, <IN> line 7."

      I've looked at the Net::FTP module, and there is some code RE 'firewall'; my PERL is not strong enough to decypher...

      Suggestions?

      PH
        When I've seen that error it means you have the libnet that was distributed with activeperl. What you need to do is run ppm (it's in your perl dir), and type install libnet. It will then download and run the installation, since you already have part of libnet installed it will ask you if you want to replace it, say yes.

        PS - Sorry I didn't get back to you sooner, I was sick yesterday.

Re: PERL backup routine
by zigster (Hermit) on Jan 16, 2001 at 21:16 UTC
    Explain what the problem is as clearly as you can and I am sure there are people here that will be able to help.
    --

    Zigster
      Thanks for the response: Here's the system call I've been trying to make (to NT/2K). $sourcedir = "J:/sortdata/sortsafe/probers/prbrsort/EG_ROOT/PRODUCTS"; $timestamp = ($targetdir.$date); mkdir ($timestamp) || die "Cannot mkdir $targetdir: $!"; @args = ("xcopy $sourcedir $timestamp"); system(@args) == 0 || die "Cannot xcopy @args"; I'll play a bit more the the ftp stuff; have already installed net::ftp, but may have proxy issues... Thanks again PH
        Use code tags to ensure your code is formatted correctly. Here is your code nicely formatted:
        $sourcedir="J:/sortdata/sortsafe/probers/prbrsort/EG_ROOT/PRODUCTS"; $timestamp=($targetdir.$date); mkdir ($timestamp) || die "Cannot mkdir $targetdir: $!"; @args = ("xcopy $sourcedir $timestamp"); system(@args) == 0 || die "Cannot xcopy @args";
        What error are you having? How do you set $date? Check out System for details of how to call system What you are doing is fine and dandy but I believe the intent is ("xcopy",$sourcedir,$timestamp). Does anyone else know why this is and what difference it makes?

        I would recomend printing @args and try running the command by hand to see if your command is correctly formatted.
        --

        Zigster