2 ## Generic data connection package
5 package Net::FTP::dataconn;
8 use vars qw(@ISA $timeout $VERSION);
12 @ISA = qw(IO::Socket::INET);
17 ${*$data}{'net_ftp_bytesread'} = 0;
23 my $ftp = ${*$data}{'net_ftp_cmd'};
25 # no need to abort if we have finished the xfer
27 if ${*$data}{'net_ftp_eof'};
29 # for some reason if we continously open RETR connections and not
30 # read a single byte, then abort them after a while the server will
31 # close our connection, this prevents the unexpected EOF on the
32 # command channel -- GMB
33 if(exists ${*$data}{'net_ftp_bytesread'}
34 && (${*$data}{'net_ftp_bytesread'} == 0)) {
36 my $timeout = $data->timeout;
37 $data->can_read($timeout) && sysread($data,$buf,1);
40 ${*$data}{'net_ftp_eof'} = 1; # fake
42 $ftp->abort; # this will close me
48 my $ftp = ${*$data}{'net_ftp_cmd'};
50 $data->SUPER::close();
52 delete ${*$ftp}{'net_ftp_dataconn'}
53 if exists ${*$ftp}{'net_ftp_dataconn'} &&
54 $data == ${*$ftp}{'net_ftp_dataconn'};
60 my $ftp = ${*$data}{'net_ftp_cmd'};
62 if(exists ${*$data}{'net_ftp_bytesread'} && !${*$data}{'net_ftp_eof'}) {
64 $data->read($junk,1,0);
65 return $data->abort unless ${*$data}{'net_ftp_eof'};
70 $ftp->response() == CMD_OK &&
71 $ftp->message =~ /unique file name:\s*(\S*)\s*\)/ &&
72 (${*$ftp}{'net_ftp_unique'} = $1);
74 $ftp->status == CMD_OK;
80 local *timeout = \$_[0]; shift;
85 return 1 unless $timeout;
88 vec($rin,fileno($data),1) = 1;
90 $win = $rw ? undef : $rin;
91 $rin = undef unless $rw;
93 my $nfound = select($rin, $win, undef, $timeout);
104 local *timeout = \$_[0];
106 $data->_select($timeout,1);
112 local *timeout = \$_[0];
114 $data->_select($timeout,0);
121 ${*$ftp}{'net_ftp_cmd'};
127 ${*$ftp}{'net_ftp_bytesread'} || 0;