in reply to Re: Re: Re: Re: Re: Problem using Net::FTP
in thread Problem using Net::FTP
the first file will be renamed, send and backuped correctly,.............. chdir "/var/files" or die "/var/files: $!\n"; -f "/var/files/info" or die "No info NO TRANSFER !\n"; my @ftp_locations = ($directory_1, $directory_2); # open the file safely or complain it wouldn't open open(FILE, "<", "info") or die "Failed to open info file: $!"; for(my $i = 1; $i <= 2; $i++) { $_ = <FILE>; s/\W*$//; # remove trailing whitespace next if (!$_); # skip empty lines # check that we get our match. If not, # complain and move on. Want to see two # filenames. unless(/^([\w.-]+) \s+ ([\w.-]+)$/x) { print STDERR "$_ is not a valid line"; next; } my ($old, $new) = ($1, $2); unless( -e $old ) { print STDERR "$old does not exist!\n"; next; } rename $old, $new; # Now that we have our filenames, grab an # ftp directory from the list unless(@ftp_locations) { die "Not enough specified ftp_locations for ". "given number of files!"; } my $destination = shift @ftp_locations; # create backup subfolder my @dt = localtime; my $subfolder_name = ((((1900 + $dt[5]) * 100 + 1 + $dt[4]) * 100 + $d +t[3]) * 100 + $dt[2]) * 100 + $dt[1]; mkdir "/var/files/out/$subfolder_name" or die "$subfolder_name: $!"; unless(move("$new", "/var/files/out/$subfolder_name")) { print STDERR "Oops! Couldn't move the file: $!"; } chdir "/var/files/out/$subfolder_name" or die "/var/files/out/$subfold +er_name: $!\n"; # ftp transfer my $ftp = Net::FTP->new ($server, Timeout => 9000, Debug => 3) +; $ftp or die "$server: cannot connect: $@"; # If you don't use ~/.netrc $ftp->login ($user,$password) or die "$_: cannot logon: " . $ftp->message; # change remote directory for the first file $ftp->cwd($destination); # Send file to ftp server $ftp->put($new) or die "$server: cannot put $new: " . $ftp->message; #Quit FTP When finished $ftp->quit; # Sleep for 20 minutes before processing next file. sleep (20 * 60) }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: Re: Re: Problem using Net::FTP
by jarich (Curate) on Mar 16, 2004 at 01:29 UTC | |
by cc (Beadle) on Mar 25, 2004 at 11:45 UTC | |
by jarich (Curate) on Mar 31, 2004 at 01:30 UTC | |
by cc (Beadle) on Apr 22, 2004 at 17:26 UTC | |
by jarich (Curate) on May 10, 2004 at 05:06 UTC | |
|