LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Perl - Net::FTP - download all PDF files (http://www.linuxquestions.org/questions/programming-9/perl-net-ftp-download-all-pdf-files-737355/)

noir911 07-02-2009 10:20 PM

Perl - Net::FTP - download all PDF files
 
I'm using Perl's Net::FTP to download some files. At the moment it is downloading only one file. I want to download all PDF files. Can someone please show me how do I do that? Thanks.

Here's my code:

Code:

#!/usr/bin/env perl

use strict;
use warnings;
use sigtrap;
use diagnostics;

use Net::FTP;

my $host="192.168.25.25";
my $directory="report/marketing/outgoing/day";
my $username = "user";
my $password = "password";
my $filename = "file_1.pdf";

my $ftp = Net::FTP->new($host, Debug => 0)
or die "Cannot connect to marketing: $@";

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

$ftp->cwd($directory)
      or die "Cannot change working directory ", $ftp->message;

$ftp->get($filename)
      or die "get failed ", $ftp->message;

$ftp->quit;


Tinkster 07-03-2009 12:39 AM

Well ... guess you'll want to retrieve a directory listing,
filter out the PDFs and retrieve them in a loop?



Cheers,
Tink

Su-Shee 07-03-2009 02:35 AM

That seems what you have to do - see this thread for suggestions:

http://www.perlmonks.org/?node_id=32298

Or, you just try wget with -Apdf

j-ray 07-03-2009 06:43 AM

try
$filename="*.pdf";

i guess that will work

kike_coello 07-03-2009 11:25 AM

i agree with tinkster, i did something like that before, what you want to do is get a list of the files you want and then select only the pdf files, after that just use a for loop

enrique


All times are GMT -5. The time now is 11:17 AM.