CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
help with ftp client program



Sep 10, 2002, 9:19 AM

Post #1 of 4 (2626 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;


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.


p.s. I can post the script if you need to see it.


Sep 10, 2002, 9:54 AM

Post #2 of 4 (2623 views)
Re: [jamesfinnegan] help with ftp client program [In reply to] Can't Post

Couldn't you save your self oodles of effort by using Net::FTP?


Sep 10, 2002, 12:15 PM

Post #3 of 4 (2618 views)
Re: [jamesfinnegan] help with ftp client program [In reply to] Can't Post

If I were to use Net::FTP is there a place to find out about return codes. I am curious as to the command:

$ftp = Net::FTP->new("", Debug => 0);

with this you can use a timeout value. How do I know if the server is unavailable connection wise or the timeout value has been hit. I believe if it is NULL then the connection cannot be made. Thanks.



Sep 11, 2002, 7:05 AM

Post #4 of 4 (2614 views)
Re: [jamesfinnegan] help with ftp client program [In reply to] Can't Post

Another question on Net::FTP. If I were to run in debug mode is there a way to extract the information in a perl script. For instance I'm getting this error when running my program:

Net::FTP=GLOB(0x2020c36c)>>> user rtc
Net::FTP=GLOB(0x2020c36c)<<< 331 Password required for rtc.
Net::FTP=GLOB(0x2020c36c)>>> PASS ....
Net::FTP=GLOB(0x2020c36c): Timeout at /usr/local/probes/runhostftp line 37

How do I extract the Timeout within the script. Thanks.



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives