|
发表于 2003-12-11 01:07:38
|
显示全部楼层
回复: 怎么使用 Net::FTP?
#!/usr/bin/perl -w
use strict;
use Net::FTP;
use constant HOST => 'nic.funet.fi';
use constant DIR => '/pub/doc/unix/run/';
use constant FILE => 'Ind.ic.Z';
use constant SIZE => '/pub/doc/unix/run/Ind.ic.Z' ;
use constant DIRA => '/pub/doc/unix/ ';
use constant DIRB => '/pub/';
my $ftp=Net::FTP->new(HOST); #<-- 多了); 應該是,
Timeout => 130,
Port => 21,
BlockSize = 10200) or die "could not connect\n";
# BlockSize default=10240;port=21;timeout=120
$ftp ->login('anonymous') or die $ftp ->message;
$ftp ->accii; #<-- ascii 才對
$ftp ->binary;
$ftp ->( "OLDNAME" , "NEWNAME" ); #<-- 這兩行幹什麼的?~~
$ftp ->delete(" FILENAME " ); #
$ftp ->cwd (DIR) or die $ftp ->message;
$ftp ->size(SIZE) or die $ftp ->message;
my $list=$ftp ->ls (DIRA) or die $ftp ->message; # $list 應該是@list
$ftp ->dir(DIRB) or die $ftp ->message;
$ftp ->get (FILE) or die $ftp ->message;
my $size=$ftp ->size(FILE);
print "$size\n";
$ftp ->quit;
foreach ($list) {
print "$_"; #加上\n 好看點
}
warn "ok\n"; |
|