Index: t/ftp.t
===================================================================
--- t/ftp.t (revision 352)
+++ t/ftp.t (working copy)
@@ -5,9 +5,9 @@
chdir 't' if -d 't';
@INC = '../lib';
}
- if (!eval "require Socket") {
- print "1..0 # no Socket\n"; exit 0;
- }
+# if (!eval "require Socket") {
+# print "1..0 # no Socket\n"; exit 0;
+# }
if (ord('A') == 193 && !eval "require Convert::EBCDIC") {
print "1..0 # EBCDIC but no Convert::EBCDIC\n"; exit 0;
}
@@ -22,7 +22,7 @@
}
my $t = 1;
-print "1..7\n";
+print "1..8\n";
$ftp = Net::FTP->new($NetConfig{ftp_testhost})
or (print("not ok 1\n"), exit);
@@ -54,9 +54,17 @@
$data->close;
print "not " unless $text eq $buf;
printf "ok %d\n",$t++;
+
+ $buf = '';
+ $data = $ftp->retr('libnet.tst');
+ $data->read($buf, 10);
+ $data->read($buf, length($text) - 10, 10);
+ $data->close;
+ print "not " unless $text eq $buf;
+ printf "ok %d\n",$t++;
+
$ftp->delete('libnet.tst') or print "not ";
printf "ok %d\n",$t++;
-
}
else {
print "# ",$ftp->message,"\n";
Index: Net/FTP.pm
===================================================================
--- Net/FTP.pm (revision 352)
+++ Net/FTP.pm (working copy)
@@ -1723,9 +1723,9 @@
=over 4
-=item read ( BUFFER, SIZE [, TIMEOUT ] )
+=item read ( BUFFER, SIZE, [, OFFSET] [, TIMEOUT ] )
-Read C<SIZE> bytes of data from the server and place it into C<BUFFER>, also
+Read C<SIZE> bytes of data from the server and place it into C<BUFFER> at C<OFFSET>, also
performing any <CRLF> translation necessary. C<TIMEOUT> is optional, if not
given, the timeout value from the command connection will be used.
Index: Net/FTP/I.pm
===================================================================
--- Net/FTP/I.pm (revision 352)
+++ Net/FTP/I.pm (working copy)
@@ -17,8 +17,9 @@
my $data = shift;
local *buf = \$_[0];
shift;
- my $size = shift || croak 'read($buf,$size,[$timeout])';
- my $timeout = @_ ? shift: $data->timeout;
+ my $size = shift || croak 'read($buf,$size,[$offset],[$timeout])';
+ my $offset = shift || 0;
+ my $timeout = @_ ? shift : $data->timeout;
my $n;
@@ -35,7 +36,14 @@
}
}
- $buf = substr(${*$data}, 0, $size);
+ if ($offset) {
+ if (length($buf) < $offset) {
+ $buf .= ('\0' x ($offset + 1 - length($buf)));
+ }
+ substr($buf, $offset) = substr(${*$data}, 0, $size);
+ } else {
+ $buf = substr(${*$data}, 0, $size);
+ }
$n = length($buf);
Index: Net/FTP/A.pm
===================================================================
--- Net/FTP/A.pm (revision 352)
+++ Net/FTP/A.pm (working copy)
@@ -17,8 +17,9 @@
my $data = shift;
local *buf = \$_[0];
shift;
- my $size = shift || croak 'read($buf,$size,[$offset])';
- my $timeout = @_ ? shift: $data->timeout;
+ my $size = shift || croak 'read($buf,$size,[$offset],[$timeout])';
+ my $offset = shift || 0;
+ my $timeout = @_ ? shift : $data->timeout;
if (length(${*$data}) < $size && !${*$data}{'net_ftp_eof'}) {
my $blksize = ${*$data}{'net_ftp_blksize'};
@@ -62,7 +63,15 @@
}
}
- $buf = substr(${*$data}, 0, $size);
+ if ($offset) {
+ if (length($buf) < $offset) {
+ $buf .= ('\0' x ($offset + 1 - length($buf)));
+ }
+ substr($buf, $offset) = substr(${*$data}, 0, $size);
+ } else {
+ $buf = substr(${*$data}, 0, $size);
+ }
+
substr(${*$data}, 0, $size) = '';
length $buf;