For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2008 > How to ftp all the files?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to ftp all the files?
Siegfried Heintze

2008-03-26, 7:11 pm

I'm using perl 5.8.8 on cygwin/windows 2003 server.

This worked (but it was sooooo tedious!):
$ perl -MNet::FTP -e '$ftp =Net::FTP->new("mediaftp.wiley.com", Debug=>0) or die "cannot connect"; $ftp->login("download","download") or die "cannot login"; $ftp->cwd("/product_ancillary/76/04701913/DOWNLOAD/") or die "cannot cd"; for (3..5) { print "getting $_\n" ; $ftp->get("ch". sprintf("%-2.2d",$_). " CodeSample.zip") or die "cannot get" ; } ';

Questions:

1. Is there an easier way?

2. More specifically: Are there some perl modules that will parse thestring ftp://download:download@mediaftp.wi...0CodeSample.zip and download the file with one or two function calls instead of what I did above?

3. I tried calling mget but there was no such function. How could I wild card and get all the zip files in that directory? I was looking at http://search.cpan.org/~jdlee/Net-F...02/Recursive.pm and wonderingif this would solve my problem. Can someone help me modify my fragment above so it recursively fetches the entire directory? I was not sure how to pass that function pointer in the example in the documentation.

4. Is perl the best way to do this? Would it be easier in some other language/library like bash or python or ruby?
Thanks!
Siegfried

Chas. Owens

2008-03-26, 7:11 pm

On Wed, Mar 26, 2008 at 3:49 PM, Siegfried Heintze (Aditi)
<a-siehei@microsoft.com> wrote:
> I'm using perl 5.8.8 on cygwin/windows 2003 server.
>
> This worked (but it was sooooo tedious!):
> $ perl -MNet::FTP -e '$ftp =Net::FTP->new("mediaftp.wiley.com", Debug=>0) or die "cannot connect"; $ftp->login("download","download") or die "cannot login"; $ftp->cwd("/product_ancillary/76/04701913/DOWNLOAD/") or die "cannot cd"; for (3..5) { print "g

etting $_\n" ; $ftp->get("ch". sprintf("%-2.2d",$_). " CodeSample.zip") or die "cannot get" ; } ';
>
> Questions:
>
> 1. Is there an easier way?


On Linux systems, yes. Use wget or curl.

>
> 2. More specifically: Are there some perl modules that will parse the string ftp://download:download@mediaftp.wi...0CodeSample.zip and download the file with one or two function calls instead of w

hat I did above?

Yes, IO::All and IO::All::FTP

perl -MIO::All -e
'io("ftp://mediaftp.wiley.com/product_ancillary/76/04701913/DOWNLOAD/Ch05%20CodeSample.zip")->user('download')->password('download')
> io("ch05.zip")'


>
> 3. I tried calling mget but there was no such function. How could I wild card and get all the zip files in that directory? I was looking at http://search.cpan.org/~jdlee/Net-F...02/Recursive.pm and wondering if this would solve my pro

blem. Can someone help me modify my fragment above so it recursively fetches the entire directory? I was not sure how to pass that function pointer in the example in the documentation.

get an ls of the remote directory and filter the results.

#warning untested code typed from memory
$sftp->get($_) for grep { /\.zip$/ } $sftp->ls;

>
> 4. Is perl the best way to do this? Would it be easier in some other language/library like bash or python or ruby?


If you are trying to do it from the command line then Perl is not the
best way. A utility like wget or curl is much better.

> Thanks!
> Siegfried
>




--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
Dan Fish

2008-03-26, 7:11 pm


Might want to check out ncftp client. Works very well, multiple platform
support and free! I use it for nearly all my batch ftp needs (albeit I have
only used the Solaris version...)

http://www.ncftp.com/ncftp/

-Dan

> -----Original Message-----
> From: Siegfried Heintze (Aditi) [mailto:a-siehei@microsoft.com]
> Sent: Wednesday, March 26, 2008 12:50 PM
> To: beginners@perl.org
> Subject: How to ftp all the files?
>
> I'm using perl 5.8.8 on cygwin/windows 2003 server.
>
> This worked (but it was sooooo tedious!):
> $ perl -MNet::FTP -e '$ftp =Net::FTP->new("mediaftp.wiley.com", Debug=>0)
> or die "cannot connect"; $ftp->login("download","download") or die "cannot
> login"; $ftp->cwd("/product_ancillary/76/04701913/DOWNLOAD/") or die
> "cannot cd"; for (3..5) { print "getting $_\n" ; $ftp->get("ch".
> sprintf("%-2.2d",$_). " CodeSample.zip") or die "cannot get" ; } ';
>
> Questions:
>
> 1. Is there an easier way?
>
> 2. More specifically: Are there some perl modules that will parse
> the string
> ftp://download:download@mediaftp.wi...y/76/04701913/D
> OWNLOAD/Ch05%20CodeSample.zip and download the file with one or two
> function calls instead of what I did above?
>
> 3. I tried calling mget but there was no such function. How could I
> wild card and get all the zip files in that directory? I was looking at
> http://search.cpan.org/~jdlee/Net-F...02/Recursive.pm and
> wondering if this would solve my problem. Can someone help me modify my
> fragment above so it recursively fetches the entire directory? I was not
> sure how to pass that function pointer in the example in the
> documentation.
>
> 4. Is perl the best way to do this? Would it be easier in some other
> language/library like bash or python or ruby?
> Thanks!
> Siegfried


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com