-   Programming (
-   -   Perl - Net::FTP - download all PDF files (

noir911 07-02-2009 11: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:


#!/usr/bin/env perl

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

use Net::FTP;

my $host="";
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: $@";

      or die "Cannot login ", $ftp->message;

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

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


Tinkster 07-03-2009 01:39 AM

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


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

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

Or, you just try wget with -Apdf

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


i guess that will work

kike_coello 07-03-2009 12:25 PM

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


All times are GMT -5. The time now is 10:22 PM.