CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Reopened: FTP to multiple directories and get files.

 



cuboidgraphix
User

Jul 19, 2010, 2:49 PM

Post #1 of 5 (2887 views)
Reopened: FTP to multiple directories and get files. Can't Post

Hello guys,
Sorry to bother you all again, but 3 days ago we had a major system crash and now my script it not working properly. I've tried checking and checking and I can't figure it out. So I have to turn to the professionals. Below I have the script with my remarks. Please NOTE that the script runs all the way through, but no files are being pulled via FTP. I would like to verify each step to see where exactly the error is. At this point I get an error ... "Transfer in progress... request aborted" or something like that. I feel as though the problem lies at the my @File line.


Code
 
#!/usr/bin/perl

use strict;
use warnings;
use Net::FTP;
use POSIX qw/strftime/;

my $Yday = strftime("R%y%m%d", localtime(time - 86400));

chdir "/home/AMA";
my @myDIR =('D010AMAB', 'D000AMAA', 'D010AMA9', 'D000AMA8',
'D010AMA5', 'D000AMA6', 'D010AMA7', 'D000AMA4',
'D010AMA3', 'D000AMA2', 'D010AMA1', 'D000AMA0'
);

my $ftp = Net::FTP->new("HOST", Debug => 1)
or die "Failed to connect to FTP server ";
print $ftp->message(), "\n";

$ftp->login("USER",'PASS')
or die "Failed to login to FTP server ";
print $ftp->message(), "\n";

foreach my $DIR(@myDIR){
print "changing cwd to $DIR\n\n";
$ftp->cwd("/$DIR")
or warn "Failed to cd to /$DIR ", print $ftp->message() and next;
print $ftp->message();

$ftp->ascii or warn "Unable to switch to ascii mode ";
my @file = grep { /^([^.].*)?$Yday/ } $ftp->ls(); // I would like to verify by printing the list of files in the volume.
$ftp->binary or warn "Unable to switch to binary mode ";
foreach my $file(@file){
print "retriving file '$file'\n"; // There is no print out here. Before it would say which file it is transfering. Nothing now.
$ftp->get($file)
or warn "Failed to retrieve '$file' ", print $ftp->message() and next;
print $ftp->message();
}
}



cuboidgraphix
User

Jul 22, 2010, 8:16 AM

Post #2 of 5 (2792 views)
Re: [cuboidgraphix] Reopened: FTP to multiple directories and get files. [In reply to] Can't Post

C'mon guys .... so many views and not 1 reply? Please ... can someone please give a helping hand? Fish... are you still here bro? I know you can help me man.. you know EVERYTHING!!!


FishMonger
Veteran / Moderator

Jul 22, 2010, 8:48 AM

Post #3 of 5 (2789 views)
Re: [cuboidgraphix] Reopened: FTP to multiple directories and get files. [In reply to] Can't Post

I suspect that the grep statement isn't returning any filenames.

As a test, drop the grep and dump the full list of files.

Code
use Data::Dumper # put this up with the other use statements 

# inside the foreach loop
my @files = $ftp->ls();
print Dumper \@files;
next;


Then verify that the filenames you want are in that list. If they are, then adjust the grep statement accordingly. If they're not there, then you have a problem elsewhere.


cuboidgraphix
User

Jul 22, 2010, 8:50 AM

Post #4 of 5 (2787 views)
Re: [FishMonger] Reopened: FTP to multiple directories and get files. [In reply to] Can't Post

Thanks Fish.. I knew you'd come through for me man. :) Will get right on it.


cuboidgraphix
User

Jul 22, 2010, 9:10 AM

Post #5 of 5 (2785 views)
Re: [FishMonger] Reopened: FTP to multiple directories and get files. [In reply to] Can't Post

OK i modified the code as this.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use Net::FTP;
use Data::Dumper;
use POSIX qw/strftime/;

my $Yday = strftime("R%y%m%d", localtime(time - 86400));

chdir "/home/AMA";
my @myDIR =('D010AMAB', 'D010AMA9', 'D000AMA8',
'D010AMA5', 'D000AMA6', 'D010AMA7', 'D000AMA4',
'D010AMA3', 'D000AMA2', 'D010AMA1', 'D000AMA0'
);

my $ftp = Net::FTP->new("10.24.1.18", Debug => 0)
or die "Failed to connect to FTP server ";
print $ftp->message(), "\n";

$ftp->login("GETAMA",'GETAMA')
or die "Failed to login to FTP server ";
print $ftp->message(), "\n";

foreach my $DIR(@myDIR){
print "\n\nChanging cwd to $DIR \n";
$ftp->cwd("/$DIR")
or warn "Failed to cd to /$DIR ", print $ftp->message() and next;
print $ftp->message();
my @files = $ftp->ls();
print Dumper \@files;
next;
}
print "The FTP session has ended!\n";
$ftp->quit;





OK after modifying the script this is what I got...

Changing cwd to D010AMAB
Directory changed.
$VAR1 = [];


Changing cwd to D010AMA9
Directory changed.
$VAR1 = [];

etc. etc.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives