LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-02-2009, 10:20 PM   #1
noir911
Member
 
Registered: Apr 2004
Location: Baltimore, MD
Posts: 681

Rep: Reputation: Disabled
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;
 
Old 07-03-2009, 12:39 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

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



Cheers,
Tink
 
Old 07-03-2009, 02:35 AM   #3
Su-Shee
Member
 
Registered: Sep 2007
Location: Berlin
Distribution: Slackware
Posts: 509

Rep: Reputation: 41
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
 
Old 07-03-2009, 06:43 AM   #4
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu
Posts: 1,419

Rep: Reputation: 99
try
$filename="*.pdf";

i guess that will work
 
Old 07-03-2009, 11:25 AM   #5
kike_coello
Member
 
Registered: Jul 2005
Location: maryland
Distribution: Ubuntu 9.04
Posts: 88

Rep: Reputation: 17
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl Net::FTP problem LidoShuffle Programming 2 06-02-2009 05:54 PM
Perl script to download the files from FTP server peddip Linux - Server 4 03-23-2009 09:49 AM
perl files download instead of parsed on apache2 mod-perl2 not parsing perl files zeigerpuppy Debian 1 02-16-2006 05:31 AM
Urgent Help: Perl FTP Script Using NET::FTP xboxter Programming 8 05-16-2005 06:57 PM
perl and Net::FTP question Tomasfuego Programming 0 12-17-2003 08:13 AM


All times are GMT -5. The time now is 10:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration