Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Net::FTP via CGI mystery

by rah (Monk)
on Jul 13, 2002 at 01:57 UTC ( [id://181434]=note: print w/replies, xml ) Need Help??


in reply to Net::FTP via CGI mystery

Have you tried cranking up the debug level on Net::FTP? A 2 or 3 will give you a blow by blow account of the FTP session. Maybe that will give you some idea why it dies on the ls.

Also, and this may be insignificant, shouldn't
$ftp->ls be
$ftp->ls() ?
I don't know how this could make it behave differently on the command line vs. http, but that might be worth a try.

Replies are listed 'Best First'.
Re: Re: Net::FTP via CGI mystery
by George_Sherston (Vicar) on Jul 13, 2002 at 12:52 UTC
    I tried increasing the debug level as you suggest, and it leaves me more baffled, but in a more specific way. First, I boiled down the script to the absolute minimum necessary to recreate the problem. It's now:
    #!/usr/bin/perl -w use strict; use Net::FTP; #use CGI::Carp qw(fatalsToBrowser warningsToBrowser); my $ftp = Net::FTP->new("ftp.xxxxx.xxx"); $ftp->pasv; $ftp->login('xxx','xxx'); my @files = $ftp->ls('/tst') or die "could not do ls"; print "Content-Type: text/html\n\n"; print "$_\n" for @files; print "done\n";
    Now, it still works fine when run from the command line, and fails when run from the browser. When it fails in the browser I just get an internal server error, because I deleted CGI::Carp, but reviewing the error logs shows the following (n.b. I tried this with a different ftp server too, so I really think that the problem is here):

    Output from the script when run from the COMMAND LINE

    Net::FTP: Net::FTP(2.61) Net::FTP: Exporter(5.562) Net::FTP: Net::Cmd(2.20) Net::FTP: IO::Socket::INET(1.25) Net::FTP: IO::Socket(1.26) Net::FTP: IO::Handle(1.21) Net::FTP=GLOB(0x81177a8)<<< 220 xxxxxxxx.xxx ULTRA FTP SERVER Net::FTP=GLOB(0x81177a8)>>> PASV Net::FTP=GLOB(0x81177a8)<<< 530 Please login with USER and PASS. Net::FTP=GLOB(0x81177a8)>>> user xxx Net::FTP=GLOB(0x81177a8)<<< 331 Password required for xxx. Net::FTP=GLOB(0x81177a8)>>> PASS .... Net::FTP=GLOB(0x81177a8)<<< 230 CyBo welcomes replicant xxx. Net::FTP=GLOB(0x81177a8)>>> PASV Net::FTP=GLOB(0x81177a8)<<< 227 Entering Passive Mode (XXX,XX,XXX,XXX, +XXX,XXX). Net::FTP=GLOB(0x81177a8)>>> NLST /tst Net::FTP=GLOB(0x81177a8)<<< 150 Opening ASCII mode data connection for + file list Net::FTP=GLOB(0x81177a8)<<< 226 Transfer complete. Content-Type: text/html /tst/graphics /tst/style /tst/images done Net::FTP=GLOB(0x81177a8)>>> QUIT Net::FTP=GLOB(0x81177a8)<<< 221 Goodbye.

    Error Log report when run from the WEB BROWSER

    Net::FTP: Net::FTP(2.61) Net::FTP: Exporter(5.562) Net::FTP: Net::Cmd(2.20) Net::FTP: IO::Socket::INET(1.25) Net::FTP: IO::Socket(1.26) Net::FTP: IO::Handle(1.21) Net::FTP=GLOB(0x8286474)<<< 220 xxxxx.xxx ULTRA FTP SERVER Net::FTP=GLOB(0x8286474)>>> PASV Net::FTP=GLOB(0x8286474)<<< 530 Please login with USER and PASS. Net::FTP=GLOB(0x8286474)>>> user xxx Net::FTP=GLOB(0x8286474)<<< 331 Password required for xxx. Net::FTP=GLOB(0x8286474)>>> PASS .... Net::FTP=GLOB(0x8286474)<<< 230 CyBo welcomes replicant xxx. Net::FTP=GLOB(0x8286474)>>> PORT XXX,XX,XXX,XXX,XXX,XXX Net::FTP=GLOB(0x8286474)<<< 200 PORT command successful. Net::FTP=GLOB(0x8286474)>>> NLST /tst Net::FTP=GLOB(0x8286474)<<< 425 Can't build data connection: Connectio +n refused could not do ls at ftp.pl line 9. Net::FTP=GLOB(0x8286474)>>> QUIT Net::FTP=GLOB(0x8286474)<<< 221 Goodbye.
    So... it seems that what's happening is that when run from the browser the script doesn't go into passive mode (whatever that means)... but I thought it already was in passive mode. I'm completely out of my depth here, and I would be most grateful for a steer on how to get this to work.

    § George Sherston

      The following extract from the wsftp help might clarify things a little?

      Passive Transfers (definition) Normally, when you connect to an FTP site, the site establishes the da +ta connection to your PC (the client). However, if the site allows pa +ssive transfers, you can have your PC establish the data connection. We recommend that you use passive mode for most transfers. Note that p +assive mode may be required for users who are behind some types of ro +uter-based firewalls or behind a gateway requiring passive transfers.

      My only thought is that maybe one way is bypassing a proxy/firewall and the other isn't? HTH.

        I don't *think* that's the problem, because in both cases the attempt to access the remote ftp server is coming from the same place - namely my script. The only difference is in where I'm calling the script from, as far as I can see. Also, it logs in to the remote ftp server either way I call it. But it seems that, called from the browser, it doesn't send a PASV command to the ftp server. I'm not sure why, or why this is a bad thing. But what I really want to know is... how do I make it work??

        § George Sherston

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://181434]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2025-07-20 09:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.