in reply to Re: Asynchronous FTP 2
in thread Asynchronous FTP 2
while for uploading a file one can use the write method:my $file = 'some_file'; my $size = $ftp->size($file); my $bsize = 1024; my $report_size = $bsize * 1000; my ($len, $buffer); my $so_far = 0; my $chunk_size = 0; $ftp->binary; my $data = $ftp->retr($file); open(my $fh, '>', $file) or die qq{Cannot open $file: $!}; binmode $fh; do { $len = $data->read($buffer, $bsize); $so_far += $len; $chunk_size += $len; if ($chunk_size >= $report_size) { printf("Downloaded %d / %d so far\n", $so_far, $size); $chunk_size = 0; } } while ($len > 0 && syswrite($fh, $buffer, $len) == $len); print "Done!\n"; close($fh); $data->close;
my $file = 'some_file'; my $size = -s $file; my $bsize = 1024; my $report_size = $bsize * 1000; my ($len, $buffer); my $so_far = 0; my $chunk_size = 0; $ftp->binary; my $data = $ftp->stor($file); open(my $fh, '<', $file) or die qq{Cannot open $file: $!}; binmode $fh; while (sysread $fh, $buffer = "", $bsize) { $len = $data->write($buffer, length($buffer)); $so_far += $len; $chunk_size += $len; if ($chunk_size >= $report_size) { printf("Uploaded %d / %d so far\n", $so_far, $size); $chunk_size = 0; } } print "Done!\n"; close($fh); $data->close;
|
|---|