hi

I need HELP to change this perl script.
Jarich is an excellent programmer and she helped me a lot before.
this script is looking for and opens this INFO text file:
...................................
FILE1 NN20000610
FILE2 ZZ20000610
...................................
renames the first file from FILE1 to NN20000610, sends it via ftp to the remote_directory_1,
waits 20 minutes,
renames the second filr from FILE2 to ZZ20000610 ans sends via ftp to the remote_directory_2

it works well,but my really problem is I cannot send a second file, if the first file was not processed.
that means, if the first file will be processed correctly,it should disappear on the remote server within 10-15 minutes.

I need to change this script, after the first file was sent:
- wait 20 minutes
- try to download via ftp the first file from the remote server (from remote_directory_1)
- if the first file is still there (not processed) don't send the second file and close the program
- but if the first file is not there (it was processed correctly), send the second file immediately.
#!/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) }
if someone has time and can help me to solve this problem I'll be very happy.
greetings !

20040610 Edit by Corion: Changed title from 'need help to change this perl script'


In reply to need help with FTP script by cc

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.