Re: perl net ftp on windows



(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 , DBSMITH@xxxxxxxxxxxxxx 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 \@files:\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/
.



Relevant Pages

  • Re: Twapi get primary domain controller
    ... Next use a simple script to invoke SCM web services. ... specify must be a full path on the remote system. ... I would like to have your opinion on an idea about "remoting Twapi": ...
    (comp.lang.tcl)
  • Re: Twapi get primary domain controller
    ... undocumented) about the Win32 BackupEventLog API. ... specify must be a full path on the remote system. ... relative path, ...
    (comp.lang.tcl)
  • Re: Using remote proxy with Safari
    ... way when on the remote LAN). ... // specify IP name and address range of sites to route via proxy ... FireFox both just execute the pac file and get back the proxy ...
    (comp.sys.mac.comm)
  • Re: Using remote proxy with Safari
    ... way when on the remote LAN). ... // specify IP name and address range of sites to route via proxy ... FireFox both just execute the pac file and get back the proxy ...
    (comp.sys.mac.comm)
  • Re: Create simple file share on the fly
    ... share by the name that I specify, on the folder that I specify. ... the example called for creating the share on a remote computer, ... the script create it, the VMWare virtual machines all fail to be able ... with spawned virtual machines. ...
    (microsoft.public.windowsxp.security_admin)