2 ## Generic data connection package
5 package Net::FTP::dataconn;
8 use vars qw(@ISA $timeout $VERSION);
13 @ISA = qw(IO::Socket::INET);
18 ${*$data}{'net_ftp_bytesread'} = 0;
24 my $ftp = ${*$data}{'net_ftp_cmd'};
26 # no need to abort if we have finished the xfer
28 if ${*$data}{'net_ftp_eof'};
30 # for some reason if we continously open RETR connections and not
31 # read a single byte, then abort them after a while the server will
32 # close our connection, this prevents the unexpected EOF on the
33 # command channel -- GMB
34 if(exists ${*$data}{'net_ftp_bytesread'}
35 && (${*$data}{'net_ftp_bytesread'} == 0)) {
37 my $timeout = $data->timeout;
38 $data->can_read($timeout) && sysread($data,$buf,1);
41 ${*$data}{'net_ftp_eof'} = 1; # fake
43 $ftp->abort; # this will close me
49 my $ftp = ${*$data}{'net_ftp_cmd'};
51 $data->SUPER::close();
53 delete ${*$ftp}{'net_ftp_dataconn'}
54 if exists ${*$ftp}{'net_ftp_dataconn'} &&
55 $data == ${*$ftp}{'net_ftp_dataconn'};
61 my $ftp = ${*$data}{'net_ftp_cmd'};
63 if(exists ${*$data}{'net_ftp_bytesread'} && !${*$data}{'net_ftp_eof'}) {
65 $data->read($junk,1,0);
66 return $data->abort unless ${*$data}{'net_ftp_eof'};
71 $ftp->response() == CMD_OK &&
72 $ftp->message =~ /unique file name:\s*(\S*)\s*\)/ &&
73 (${*$ftp}{'net_ftp_unique'} = $1);
75 $ftp->status == CMD_OK;
79 my ($data, $timeout, $do_read) = @_;
80 my ($rin,$rout,$win,$wout,$tout,$nfound);
82 vec($rin='',fileno($data),1) = 1;
84 ($win, $rin) = ($rin, $win) unless $do_read;
87 $nfound = select($rout=$rin, $wout=$win, undef, $tout=$timeout);
112 ${*$ftp}{'net_ftp_cmd'};
118 ${*$ftp}{'net_ftp_bytesread'} || 0;