Okay, the problem is that you're ftping as many files as the info file provides you with. If this usually contains 2 files then that's great, but you probably want to allow it to later contain 3 or 4 or more, for flexibility's sake.

If you're happy with this idea, then you'll probably realise that specifying the directory that you want the file to be ftped into inside the info file, with the renaming information is a good idea.

Before I get to that I just want to bring up one problem I immediately had with your script:

open(FILE, "<info>"); while (<FILE> ) {

Firstly, I don't think you actually mean to have that > there. Secondly you're not checking that your open succeeded. What if you're not allowed to read the file? Permission denied? You should definately check this.

So anyway, we can fix your code like this:

# 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 unless(/^(.+?) \s+ (.+?) \s+ (.+?)$/x) { print STDERR "$_ is not a valid line"; next; } my ($old, $new, $ftpdir) = ($1, $2, $3); rename $old, $new; # 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@adress') or die "$_: cannot logon: " . $ftp->message; # change remote directory for the first file $ftp->cwd($ftpdir); # use directory from file # 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) }

I really don't like your regular expression to pull the filenames out of the line. It's open to getting all sorts of things wrong. I'd suggest you instead change it to something like:

#Expect 2 filenames and a directory path /^([\w._-] \s+ ([\w._-]) \s+ ([\w._\/-]$)/;
This prevents people from entering the following lines and getting interesting results:
/home/jarich/passwd /etc/passwd abc a b c
In the first case it's pretty easy to spot what $1, $2 and $3 are set to and I hope you understand why that might be a bad thing. In the second case we get this:
$1 = "a "; $2 = "b "; $3 = "c"
Why all those spaces when you have \s+? Because .* is greedy from the left, not from the right.

I'd suggest you work out what characters you want to allow in your filenames and only accept those. I've given you a good start. [\w._-] only accepts letters, numbers, dots, underscores and dashs. If you need anything else then add that in... with caution. Oh, and make sure you add them before the dash, not after. This will probably help you in the future too.

One final thing. Notice how using identation makes the script easier to read? You might want to make a special effort on that next time you post here.

all the best, and I hope this helps

jarich


In reply to 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.