in reply to need help with FTP script

After your sleep, you just want to check whether $destination/$new is still there, right? So you repeat the connection and navigate to the directory, do an ls, and look for the file. Something like (absolutely untested):
# This is just like the section before the sleep, but it's aft +er $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); # # this is new my $found = grep /\Q$new\E/, $ftp->ls; if ($found) { die "The file is still there!\n" }

The PerlMonk tr/// Advocate

Replies are listed 'Best First'.
Re^2: need help with FTP script
by cc (Beadle) on Jun 11, 2004 at 12:33 UTC
    hi Roy

    thanks for your time and help
    about your question:
    I have to send the first file in each cases.
    after 20 minutes sleep I have to check if the first file is still on the remote server in $remote_directory_1 or not.
    only if the first file is not there (in $remote_directory_1), I can send the second file.

    I changed the code :
    ...................................................................... +. # 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) $ftp = Net::FTP->new ($server, Timeout => 9000, Debug => 3); # + (this is 172 line) $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); # # this is new my $found = grep /\Q$new\E/, $ftp->ls; if ($found) { die "The file is still there!\n" } ...................................................................... +... # ftp transfer
    but I get following error:
    "Scalar found where operator expected at send.cgi line 172, near ")
    $ftp"
    (Missing operator before $ftp?)
    syntax error at ftp5.cgi line 172, near ")
    $ftp "
    Execution of ftp5.cgi aborted due to compilation errors."

    the 172 line is:
    $ftp = Net::FTP->new ($server, Timeout => 9000, Debug => 3); # (this is 172 line)

    any idea what could be wrong ?

    kind regards
    cc
      You're missing a semicolon on the previous line.

      We're not really tightening our belts, it just feels that way because we're getting fatter.
        thanks Roy

        it works perfectly now !

        greetings
        cc
        hi Roy

        I have a question.
        I try to send an error mail, when the transfer was not completed, but I don't get any mails.
        Path to sendmail and recipient address are correct:
        ...................................................................... +... # check if the first file is still there my $found = grep /\Q$new\E/, $ftp->ls; if ($found) { die "The file is still there !\n" and next; { # send mail if transfer not completed open(MAIL, "|/usr/sbin/sendmail -t") || die "Cant send mail. Reason: +$!"; print MAIL "from:$sender\n"; print MAIL "to:$recipient\n"; print MAIL "subject: transfer was not completed !\n"; print MAIL "transfer of second file failed ! \n"; print MAIL "Time: ", scalar localtime, "\n"; close(MAIL); } } #quit FTP when finished $ftp->quit; ...................................................................... +...
        and I don't get any errors.

        greetings
        cc