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

Hi, I would like to log in to a tcp and get a file from there. Tried with this ;
require "ftp.pl"; $ftpHost = "x.x.x.x"; if (&ftp::open($ftpHost,21,0,1) != 1) { die "Can't open $ftpHost\n"; } if (&ftp::login("name","pwd") != 1) { die "Can't login to $ftpHost\n"; } if (($pwd = &ftp::pwd) eq "") { die "Can't get current directory\n"; } print "pwd = $pwd\n"; $newCwd = "/perl"; if (&ftp::cwd($newCwd) != 1) { die "Can't cwd to $newCwd \n"; } if (&ftp::dir_open !=1 ) { die "Can't open directory for reading\n"; } print "Directory listing for $newCwd:\n"; while (&ftp::read() > 0) { print $ftp::buf; } if (&ftp::dir_close != 1) { die "can't close directory read\n"; } $file = "x.pm"; print "Getting $file \n"; #if (&ftp::get($file,"NewName") != 1) if (&ftp::get($file) != 1) { die "Can't get $file\n"; } &ftp::close;
but it gave me this :
Can't locate sys/socket.ph in @INC (did you run h2ph?) (@INC contains: /usr/lib/perl5/5.6.1/i386-lin ux /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /us r/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.6.1/i386-linux /us r/lib/perl5/vendor_perl/5.6.1 /usr/lib/perl5/vendor_perl .) at /usr/lib/perl5/5.6.1/chat2.pl line 18

I checked and there is no sys/socket.ph. May I know what the problem is and how to solve it ?

next step is, I need to put this into the web, how do I integrate the file into website or what CGI should I write to execute(trigger) this program ? Thanks

Edit: Added <code> tags, larsen

edited by ybiC: retitle from "tcp cnx"

Replies are listed 'Best First'.
Re: ftp.pl to retrieve a file
by esh (Pilgrim) on Aug 15, 2003 at 11:59 UTC

    Don't use ftp.pl. The first sentence in that file states:

    This library is no longer being maintained, and is included for backward compatibility with Perl 4 programs which may require it.

    Instead, check out Net::FTP or LWP.

    Here is an example stolen from Net::FTP documentation:

    use Net::FTP; $ftp = Net::FTP->new("some.host.name", Debug => 0); $ftp->login("anonymous",'-anonymous@'); $ftp->cwd("/pub"); $ftp->get("that.file"); $ftp->quit;

    As for your next question...

    I need to put this into the web, how do I integrate the file into website or what CGI should I write to execute(trigger) this program
    ... you're going to need to be more specific in describing exactly what you want to do.

    If all you want to do is show a file from an FTP site when a user clicks on a link, consider linking directly to the file on that FTP site. Browsers know how to do FTP.

    <a href="ftp://some.host.name/pub/that.file">click here</a>

    If the FTP site requires a username and password and you don't mind letting the whole world know what they are, use:

    <a href="ftp://username:password@some.host.name/pub/that.file">click h +ere</a>

    -- Eric Hammond

Re: ftp.pl to retrieve a file
by liz (Monsignor) on Aug 15, 2003 at 10:15 UTC
    ...did you run h2ph...

    It says so in the error message! Have you tried doing a perldoc h2ph?

    I leave the rest as an excercise to the reader.

    Liz