
jamesfinnegan
Novice
Sep 10, 2002, 9:19 AM
Post #1 of 4
(853 views)
|
|
help with ftp client program
|
Can't Post
|
|
I'm trying to write a socket program involving an ftp client. I set it up with 2 sockets, bind both, then connect the first socket to port 21. I then send information such as username, password, passive data, etc. This all works fine. At this point I do a listen on socket2. I then do a send data on socket 1 to retrieve a file I know exists. This is where I'm having the trouble. I know the data is supposed to transfer across port 20. I'm attempting to use the select function so I don't block forever. However when using the select the program is timing out. I do the listen on socket2 and then issue this command $readmask = &fhbits(SOCK2); $rc = select($readmask, undef, undef, 10); if ($rc < 1) { &time_error() } The readmask contains the fhbits routine: my @fhlist = @_; my $bits; my $filehandle; for $filehandle (@fhlist) { vec($bits, fileno($filehandle),1) = 1; } return($bits); After the select finishes I am expecting to do an accept. I have setup a dummy socket called rsock which looks like the following: local( $sockaddr_r, $port ); local( $type, $myaddr, $a, $b, $c, $d ); local( $mysockaddr, $family, $hi, $lo ); $sockaddr_r = 'S n a4 x8'; if( ! socket( RSOCK, PF_INET, SOCK_STREAM, $proto )) { warn "socket: $!"; print "no socket available, returning 0\n" if ($verbose ne "-f"); return 0; } and the accept will look like: $acc = accept(SOCK2,RSOCK) || die "cannot accept socket connection\n"; Then I expect to read from the remote socket. Can anyone tell me if the sequence is correct? Am I supposed to issue the select right after the attempt to retrieve the file. Or am I supposed to accept the connection from the remote side first? Thanks for any help. Jim p.s. I can post the script if you need to see it.
|