(this list replies to the poster, not to the list unless I specify to list--I'm
growing accustomed)
(here's one for the list) (hopefully in the future I just send to list by
remembering to specify so)

On Thu, 29 Dec 2005 13:08 , [EMAIL PROTECTED] sent:
>I cannot figure out how Net::FTP set its local current directory for gets
>of remote files?  Does anyone know?
>I want to get remotefile from remotehost using:
>but I want to place this file in $localdir not in what Net::FTP claims to

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

Sorry, I don't use Win much.  That worked for me on Linux.

also, instead of using  LOCAL_FILE
I used chdir builtin function (2 different ways to do it).  see next code
(includes those 2 different ways to do it) it downloads 3 small html files from 
a
CPAN mirror site.  Might be easier just to chdir to the dir where you want the
file to be saved (since it saves in C-urrent W-orking D-irectory if given no
specification otherwise).

#!/usr/bin/perl -w

use strict;
use Net::FTP;
use Cwd;

my $ch_dir = '/home/al/tmp2';

print "cur_dir is:\n";
print cwd, "\n\n";

chdir( $ch_dir ) or die "Cant chdir to $ch_dir $!";
print "cur_dir is:\n";
print cwd, "\n";

my $ftp = Net::FTP->new("cpan.mirrors.tds.net", Debug => 0)
             or die "Cannot connect to some.host.name: $@";

$ftp->login("anonymous",'-anonymous@')
             or die "Cannot login ", $ftp->message;

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


my @files=$ftp->ls
or die "Cannot open the directory",$ftp->message;
# print @files, "\n\n";

print "-------------------------------------------------\n";
print "Here are [EMAIL PROTECTED]:\n";
foreach ( @files ) {
print $_, "\n";
}
print "-------------------------------------------------\n";

print "Here are readme\*:\n";
foreach ( @files ) {
print $_, "\n" if /readme/i;
}
print "-------------------------------------------------\n";

my $localdir = '/home/al/tmp2/';
my @got_list;
print "Here are get\/got list:\n";
foreach ( @files ) {
chomp;
if ( /(^rea|^si|^di).*\.html/i ) { # get these
push @got_list, $_;

# use either but not both of the next two lines
$ftp->get($_) or die "get failed ", $ftp->message;
# $ftp->get($_, "$localdir$_") or die "get failed ", $ftp->message;
}
}
print @got_list, "\n";
# end

-- 
Alan.


---- Msg sent via CWNet - http://www.cwnet.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to