2009-11-18 2 views
1

FTP 펄 스크립트가 있는데 원격 서버로 전송되는 바이트 수가 로컬 서버에있는 파일의 실제 바이트 수와 같은지 확인하여 파일 전송이 완료되었는지 확인하려고합니다. 내가 어떻게 이걸 이룰 수 있니? 당신은 크기()Perl을 사용하여 FTP를 통해 파일 크기를 확인하려면 어떻게해야합니까?

 
size (FILE) 

Returns the size in bytes for the given file as stored on the remote server. 

NOTE: The size reported is the size of the stored file on the remote 
server. If the file is subsequently transferred from the server in ASCII 
mode and the remote server and local machine have different ideas about 
"End Of Line" then the size of file on the local machine after transfer 
may be different. 

코드가 사용할 수있는, 워드 프로세서에서

my $ftp = Net::FTP->new($host, Debug => 1) 
or die "Could not connect to '$host': [email protected]"; 

$ftp->login($user, $pw) 
or die sprintf "Could not login: %s", $ftp->message; 

$ftp->cwd($path) 
or die sprintf "Could not login: %s", $ftp->message; 

$ftp->ls; 

$ftp->binary; 

$ftp->get($file) 
or die sprintf "Could not login: %s", $ftp->message; 

답변

6

: 여기

내가 지금까지 가지고 무엇

my $host="127.0.0.1"; 
my $user="anonymous"; 
my $pw = "asdfsf"; 
my $path="pub"; 
my $file="file"; 
my $ftp = Net::FTP->new($host, Debug => 0) 
    or die "Could not connect to '$host': [email protected]"; 

$ftp->login($user, $pw) or die sprintf "Could not login: %s", $ftp->message; 
$ftp->cwd($path) or die sprintf "Could not login: %s", $ftp->message; 
$ftp->binary; 
print $ftp->size($file) or die sprintf "Could not login: %s", $ftp->message; 
$ftp->quit(); 
+0

이 괜찮를하지만, 원격 파일 전송 및 크기 전에 로컬 파일 크기를 comapre 싶습니다. r 전송. 어떻게 할 수 있습니까? – Vijay

+0

perldoc -f stat – ghostdog74

3
print "FTP size = ", $ftp->size($file), "\n"; 
print "Local size = ", (-s $file), "\n"; 
+0

ftp를 바이너리 모드로 설정하지 않으면 작동하지 않습니다 : $ ftp-> binary; – Fa11enAngel

관련 문제