2 ## Generic data connection package
5 package Net::FTP::dataconn;
8 use vars qw(@ISA $timeout);
11 @ISA = qw(IO::Socket::INET);
16 ${*$data}{'net_ftp_bytesread'} = 0;
22 my $ftp = ${*$data}{'net_ftp_cmd'};
24 # no need to abort if we have finished the xfer
26 if ${*$data}{'net_ftp_eof'};
28 # for some reason if we continously open RETR connections and not
29 # read a single byte, then abort them after a while the server will
30 # close our connection, this prevents the unexpected EOF on the
31 # command channel -- GMB
32 if(exists ${*$data}{'net_ftp_bytesread'}
33 && (${*$data}{'net_ftp_bytesread'} == 0)) {
35 my $timeout = $data->timeout;
36 $data->can_read($timeout) && sysread($data,$buf,1);
39 ${*$data}{'net_ftp_eof'} = 1; # fake
41 $ftp->abort; # this will close me
47 my $ftp = ${*$data}{'net_ftp_cmd'};
49 $data->SUPER::close();
51 delete ${*$ftp}{'net_ftp_dataconn'}
52 if exists ${*$ftp}{'net_ftp_dataconn'} &&
53 $data == ${*$ftp}{'net_ftp_dataconn'};
59 my $ftp = ${*$data}{'net_ftp_cmd'};
61 if(exists ${*$data}{'net_ftp_bytesread'} && !${*$data}{'net_ftp_eof'}) {
63 $data->read($junk,1,0);
64 return $data->abort unless ${*$data}{'net_ftp_eof'};
69 $ftp->response() == CMD_OK &&
70 $ftp->message =~ /unique file name:\s*(\S*)\s*\)/ &&
71 (${*$ftp}{'net_ftp_unique'} = $1);
73 $ftp->status == CMD_OK;
79 local *timeout = \$_[0]; shift;
84 return 1 unless $timeout;
87 vec($rin,fileno($data),1) = 1;
89 $win = $rw ? undef : $rin;
90 $rin = undef unless $rw;
92 my $nfound = select($rin, $win, undef, $timeout);
103 local *timeout = \$_[0];
105 $data->_select($timeout,1);
111 local *timeout = \$_[0];
113 $data->_select($timeout,0);
120 ${*$ftp}{'net_ftp_cmd'};