Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Perl / Modules / September 2003



Tip: Looking for answers? Try searching our database.

Net::FTP thru firewall

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sisyphus - 27 Sep 2003 08:02 GMT
Hi,

Probably more of a basic ftp and (Shorewall) firewall configuration
issue, but I'll ask the question here anyway.

With the firewall running, and using the 'ftp' command line utility,
there's no problem. Here's a screenshot (debugging turned on):

ftp> cd w32perl
---> CWD w32perl
250 CWD command successful.
ftp> ls
ftp: setsockopt (ignored): Permission denied
---> PASV
227 Entering Passive Mode (203,59,24,225,7,225).
---> LIST
150 Opening ASCII mode data connection for file list
followed by a successful listing of all files.

But when I come to do the same thing with a perl script it doesn't work.

Here's the relevant section of the perl script:

 $ftp->pasv();
 $ftp->cwd('w32perl');
 @ret = $ftp->ls();
 $ftp->quit;
 for (@ret) {print $_, "\n"}

And here's the corresponding screen shot - again, the firewall is
running, debugging is turned on (and warnings are enabled):

Net::FTP=GLOB(0x82d98ec)<<< 230 User kalinabears logged in.
Net::FTP=GLOB(0x82d98ec)>>> PASV
Net::FTP=GLOB(0x82d98ec)<<< 227 Entering Passive Mode
(203,59,24,225,11,182).
Net::FTP=GLOB(0x82d98ec)>>> CWD w32perl
Net::FTP=GLOB(0x82d98ec)<<< 250 CWD command successful.
Net::FTP=GLOB(0x82d98ec)>>> PORT 203,220,176,129,134,163
Net::FTP=GLOB(0x82d98ec)<<< 200 PORT command successful.
Net::FTP=GLOB(0x82d98ec)>>> NLST

At this point the script simply hangs.
If I turn the firewall off there's no problem - so I guess that one
solution to the problem is to simply do just that before I run the
script. Another (better) solution would be to rewrite the script as a
series of system commands - but I would still like to know why the
operation works fine under one scenario, but fails under the other - if
only for the sake of my general education.

Of course I don't *really* want to have to turn the firewall off, and I
don't want to rewrite the script as a series of system commands either.
It would be far preferable to run the perl script as a Net::FTP script
if that can be done.

This is perl 5.8.0 on (mdk 9.1) linux, Net-FTP-2.65 btw.

Cheers,
Rob
Sisyphus - 28 Sep 2003 06:01 GMT
> Net::FTP=GLOB(0x82d98ec)<<< 230 User kalinabears logged in.
> Net::FTP=GLOB(0x82d98ec)>>> PASV
[quoted text clipped - 5 lines]
> Net::FTP=GLOB(0x82d98ec)<<< 200 PORT command successful.
> Net::FTP=GLOB(0x82d98ec)>>> NLST

I'm in passive mode (aren't I ?). So why is a 'port' command being sent.
I thought that only got sent in active mode.

Cheers,
Rob
Eric Wilhelm - 28 Sep 2003 15:44 GMT
>> Net::FTP=GLOB(0x82d98ec)<<< 230 User kalinabears logged in.
>> Net::FTP=GLOB(0x82d98ec)>>> PASV
[quoted text clipped - 7 lines]
> I'm in passive mode (aren't I ?). So why is a 'port' command being sent.
> I thought that only got sent in active mode.

in your earlier post, you said

    $ftp->pasv();

From perldoc Net::FTP,

pasv ()
  Tell the server to go into passive mode. Returns the text that
  represents the port on which the server is listening, this text is in a
  suitable form to sent to another ftp server using the "port" method.

Note that this tells the *server* to go into passive mode (try issuing
"passive" from the command line ftp client, note that it responds with
"Passive mode off.")

A passive client is the default setup.  Issuing PASV to the server makes
the server passive and then the client has to actively connect to the
port on which the server now listens.

Firewalls are more difficult to configure for active ftp clients, so the
chances are that you need to stay in passive mode with the client.

--Eric
Sisyphus - 28 Sep 2003 23:51 GMT
> in your earlier post, you said
>
[quoted text clipped - 6 lines]
>    represents the port on which the server is listening, this text is in a
>    suitable form to sent to another ftp server using the "port" method.

Yes - I missed the point that pasv() was acting on the *server*.

> Note that this tells the *server* to go into passive mode (try issuing
> "passive" from the command line ftp client, note that it responds with
[quoted text clipped - 8 lines]
>
> --Eric

But if I delete '$ftp->pasv();' from the script I still get:

Net::FTP=GLOB(0x82d98f4)<<< 230 User kalinabears logged in.
Net::FTP=GLOB(0x82d98f4)>>> CWD w32perl
Net::FTP=GLOB(0x82d98f4)<<< 250 CWD command successful.
Net::FTP=GLOB(0x82d98f4)>>> PORT 203,220,176,153,128,149
Net::FTP=GLOB(0x82d98f4)<<< 200 PORT command successful.
Net::FTP=GLOB(0x82d98f4)>>> NLST

at which point it hangs.

Does this indicate that the Net::FTP client default mode is 'active' ?
And, if so, is there a way to change it to 'passive' ?

Aaaarrgh!!! .... *now* I see it .... the answer to both of those
questions is 'yes' ..... I supply 'Passive=>1' as an option to
'Net::FTP->new()' ..... and all works fine.

Thanks Eric.

Cheers,
Rob

Signature

To reply by email u have to take out the u in kalinaubears.

Eric Wilhelm - 29 Sep 2003 02:12 GMT
> Aaaarrgh!!! .... *now* I see it .... the answer to both of those
> questions is 'yes' ..... I supply 'Passive=>1' as an option to
> 'Net::FTP->new()' ..... and all works fine.

There is also an environment variable (which I had to discover to get
CPAN up and running) which will serve this same function (FTP_PASSIVE or
something.)

--Eric
Sisyphus - 29 Sep 2003 04:15 GMT
> There is also an environment variable (which I had to discover to get
> CPAN up and running) which will serve this same function (FTP_PASSIVE or
> something.)
>
> --Eric

Yes, it's mentioned in the docs (as an alternative to setting 'Passive')
in pretty much the same breath.

Gee I hate missing documented info ...... but it's something I continue
to do so very easily when I don't really understand what's going on.

Oh well ... maybe *next* time. And at least now I have a better
understanding of what's happening.

Cheers,
Rob

Signature

To reply by email u have to take out the u in kalinaubears.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.