http://www.perlmonks.org?node_id=146647

PriNet has asked for the wisdom of the Perl Monks concerning the following question:

my administrator is rather particular about the way i tie to my FTP server from my WWW server for security reasons. hence, i'm trying to write a "canned" FTP program that gets the directory and files from a remote server from my web server to my perl program for manipulation. i get everything working perfectly up to the point of the "LIST". my connection stales and i get nothing at this point. please check the following example and help me over this last "hump" ?
$FTPdServer = '192.168.0.1'; $System[0] = '\0'x4; $System[1] = '\0'x16; socket (FTP, AF_INET, SOCK_STREAM, getprotobyname('tcp')); connect (FTP, pack('S n a4 x8', AF_INET, 21, (gethostbyname($FTPdServe +r)) [4])); $System[0] = (unpack('S n a4 x8', getsockname(FTP)))[2]; $System[1] = pack('S n a4 x8', AF_INET, 0, $System[0]); select (FTP); $| = 1; select (STDOUT); sysread (FTP, $FormData, 1024); print STDOUT "$FormData\n"; sysread (FTP, $FormData, 1024); print STDOUT "$FormData\n"; print FTP "USER webserver\r\n"; sysread (FTP, $FormData, 1024); print STDOUT "$FormData\n"; print FTP "PASS password\r\n"; sysread (FTP, $FormData, 1024); print STDOUT "$FormData\n"; print FTP "CWD Weaving\r\n"; sysread (FTP, $FormData, 1024); print STDOUT "$FormData\n"; socket (IOS, AF_INET, SOCK_STREAM, getprotobyname('tcp')); bind (IOS, pack('S n a4 x8', AF_INET, 0, (gethostbyname($FTPdServer)) +[4])); ($System[2], $System[3], @tBuffer) = unpack("S n C C C C x8", getsockn +ame(IOS)); push(@tBuffer, ($System[3] >> 8) & 0x00ff); push(@tBuffer, $System[3] & 0x00ff); $System[4] = join(',', @tBuffer); listen (IOS, 1); print FTP "PORT $System[4]\r\n"; sysread (FTP, $FormData, 1024); print STDOUT "$FormData\n"; print FTP "LIST\r\n"; sysread (FTP, $FormData, 1024); print STDOUT "$FormData\n"; ### at this point the FTP server says; ### "opening for ascii data transfer" ### then hangs infinetly when i try the ### accept (DATA,IOS) and try to read ### from <DATA> port/file close (IOS); print FTP "QUIT\r\n"; sysread (FTP, $FormData, 1024); print STDOUT "$FormData\n"; close (FTP);