hi

thank you very much, it helps a lot.
I'm also very happy that you explain so clearly.
You are excellent teacher.
I have only some little problems and don't know how to solve it.
the first problem is this line:
unless(/^([\w.-]) \s+ ([\w.-])$/x) {
and script doesn't want to process, although file are correct.
I get this message:
"AB0000011 LA120040212 is not a valid lineBB0000012 LB20040212 is not a valid lineErrors:"
info file looks:
AB0000011 LA120040212 BB0000012 LB20040212
and I have these 2 files: AB0000011 and BB0000012
I think, I did not explain the problem so well before.
it should read the filenames in, compare them to what is in the info file and if they do not match don't process.
for example: should NOT process with above info file and these files: AB0000015 / BB0000016
the second problem is, that after transfer doesn't move these 2 files to the backup directory
this line has an error:
system("mv $new /var/save/$subfolder_name");
my third problem is, it sends the mail or moved the files without ftp transfer

#!/usr/bin/perl -w use strict; use warnings; use File::Copy; use Net::FTP; use Net::Netrc; my $linux = "....."; my $recipient = "....."; my $server = "....."; my $user = "....."; my $password = "....."; # ftp directories my $directory1 = "/ftp/B1"; my $directory2 = "/ftp/B2"; 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); 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; # 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) } # send the mail, only when transfer completed open(MAIL, "|/usr/sbin/sendmail -t") || die "Cant send mail. Reason: $ +!"; print MAIL "from:$linux\n"; print MAIL "to:$recipient\n"; print MAIL "subject: file transfer was successfully !\n"; print MAIL "file transfer was successfully ! \n\n"; print MAIL "Time: ", scalar localtime, "\n"; close(MAIL); # when transfer completed, create backup subdirectory and move all fil +e there 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/save/$subfolder_name" or die "$subfolder_name: $!"; system("mv /var/files/info /var/save/$subfolder_name"); system("mv $new /var/save/$subfolder_name"); exit;

janitored by ybiC: Balanced <code> tags around codeblock


In reply to Re: Re: Re: Re: Problem using Net::FTP by cc
in thread Problem using Net::FTP 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.