the info file looks :
----------------------
AB00001 N120001
BB00002 N200023
----------------------
However, because the code looks like:
while (<FILE> ) {
you will process as many files as the info file has lines. So, if the info file were to be replaced with something like this:
AB00001 N120001 BB00002 N200023 CB00003 N300011 DB00004 N400022
then your code will attempt to ftp and rename each of those 4 files.

If you want to limit the number of files processed to always be two and only two then you don't want to use a while loop. Perhaps a for loop would be better:

# replace the while(<FILE>) { with the following two lines for(my $i = 1; $i <= 2; $i++) { $_ = <FILE>;

script should check if the files are complete and names on info file matches to the names of this 2 files.
I have no idea what this means.

first file N120001 should be transfered to: $ftp->cwd("FTP/A1"); and second file N200023 to: $ftp->cwd("FTP/B2");
If you can't change what gets put into the info file then my suggestion the other day won't work as well. If you can change it then that would probably make better sense. This way the directory names to ftp things to aren't hard coded in your script and therefore may be easier to change in future.

Assuming you can't make the changes to the info script then you might want to change your script to look more like:

# ftp directories my @ftp_locations = ("FTP/A1", "FTP/B2"); # open the file safely or complain it wouldn't open open(FILE, "<", "info") or die "Failed to open info file: $!"; while (<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 $server = "X.X.X.X"; my $ftp = Net::FTP->new ($server, Timeout => 9000, Debug => 3) +; $ftp or die "$server: cannot connect: $@"; # If you don't use ~/.netrc $ftp->login ('anonymous', 'mail@address') 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; # Sleep for 20 minutes before processing next file. sleep (20 * 60) }
Note that this still allows you to deal with more than 2 files in the info file, but only if you add additional ftp locations into the array up the top.

when the transfer completed should create a new subdirectory with date and time, something like: 200402241200 and put (backup) all files there, otherwise files will be overwritten each time.
How about you give this bit a go and get back to us with how you do at it?

and I would like use your script, that you already posted.
Ah, but of course. Certainly, go ahead and use the code I've provided you with. Good luck with the rest.

Hope this helps,

jarich


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