cc has asked for the wisdom of the Perl Monks concerning the following question:
if someone has time and can help me to solve this problem I'll be very happy.#!/usr/bin/perl -w use strict; use warnings; use File::Copy; use Net::FTP; use Net::Netrc; my $server = "192.168.0.10"; my $user = "myuser"; my $password = "mypassword"; # ftp directories my $remote_directory_1 = "/FTP/DATA1"; my $remote_directory_2 = "/FTP/DATA2"; chdir "/ftp/IN" or die "/ftp/IN: $!\n"; -f "/ftp/IN/INFO" or die "NO INFO FILE NO TRANSFER !\n"; my @ftp_locations = ($remote_directory_1, $remote_directory_2); # open the file safely or complain it wouldn't open open(FILE, "<", "INFO") or die "Failed to open info file: $!"; # read all the lines in from INFO file my @files; for(my $i = 1; $i <= @ftp_locations; $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; } # rename the files as per rename in file my ($old, $new) = ($1, $2); unless( -e $old ) { print STDERR "$old does not exist!\n"; next; } rename $old, $new; push @files, $new; } # check that we have the number of files that we expect unless(@files == @ftp_locations) { die "Not enough specified ftp_locations for ". "given number of files!"; } # FTP each file across, die on errors foreach my $new (@files) { my $destination = shift @ftp_locations; # 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) }
20040610 Edit by Corion: Changed title from 'need help to change this perl script'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: need help with FTP script
by Roy Johnson (Monsignor) on Jun 10, 2004 at 15:16 UTC | |
by cc (Beadle) on Jun 11, 2004 at 12:33 UTC | |
by Roy Johnson (Monsignor) on Jun 11, 2004 at 15:00 UTC | |
by cc (Beadle) on Jun 12, 2004 at 09:34 UTC | |
by cc (Beadle) on Jun 15, 2004 at 21:58 UTC | |
by Roy Johnson (Monsignor) on Jun 15, 2004 at 22:06 UTC | |
| |
|
Re: need help with FTP script
by shonorio (Hermit) on Jun 10, 2004 at 14:01 UTC |