Solved

Perl FTP download not working.

Posted on 2007-04-04
2
4,224 Views
Last Modified: 2008-01-09
I have created a script to download several zip files over 50 files. There are two problems that I am running into, first there are two folders in the directory were the files are. The folders do not need to be downloaded, and the second is that the script does not download all the files it usually downloads something like 50 - 52 files I need it to download all files but not the folders here is a copy of my script please help me figuer out what I am doing wrong.

[start code]

#!/usr/bin/perl
      use Net::FTP;
      use Archive::Extract;
      use File::Listing qw(parse_dir);

      $host = 'myhost.com';
      $path = '/mydir/data/';

      $ftp = Net::FTP->new($host, Timeout => 1800) or die "Cannot contact $host: $!";

      $ftp->login('username', 'password') or die "Cannot login ($host):" . $ftp->message;

      $ftp->cwd($path) or die "Cannot change directory ($host):" . $ftp->message;

      @Files = $ftp->ls('-lR');
      
      $ftp->binary();         
      
foreach $file (parse_dir(\@Files))
      {
          my($name, $type, $size, $mtime, $mode) = @$file;            
            print "Retrieving $name \n";
            print "File type $type \n";
            
            if ($type != 'f')
            {
                  print "File name: $name";
                  print "File type: $type";
            }
            
            if ($type eq 'f')
            {
                  $ftp->hash($name,102400);
            
                  $ftp->get($name, "C:/Temp/$name") or warn "Could not get $_, skipped: $!";
                  EXTRACT("C:/temp/$name");
            }
      }

$ftp->quit or die "Could not close the connection cleanly: $!";
      
sub EXTRACT
      {
            my $ae = Archive::Extract->new( archive => @_ );
            my $ok = $ae->extract( to => 'C:/temp/central/dnld' );

      }

exit;

[code end]

one last thing I have also include a step to unzip all the files as it finishes the download. What is wrong with this thing.
0
Comment
Question by:leotron
2 Comments
 
LVL 20

Accepted Solution

by:
jmcg earned 500 total points
ID: 18880110
The fact that your script successfully downloads some files means that it is substantially correct and leads me to suspect that there is some data dependency that is causing your script to fail: running into a transfer problem from the FTP server, running out of disk space, etc.

The first thing to check is the content of @Files to be sure that it contains everything you expect it to contain. Then, if the "foreach $file" loop exits early, before all the files are transferred, I'd look at whether there's an uncaught error occurring in the 'extract' method.

For perfectionism, check whether the call to the 'hash' method is working the way you want. As I read it, you should only need to call it once per ftp session, not for every file. The $file parameter you're passing is evaluated as to true or false, but otherwise ignored.
0
 
LVL 1

Author Comment

by:leotron
ID: 19142098
Thank you for your comment the script was timing out so I increased the timeout time and that solved the problem
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now