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

I'm trying to create a simple perl script to FTP a file through a gateway using Net::FTP.

I can do this from the UNIX command line by:
- ftping the gateway "ftp ftpgateway.mycompany.com"
- logging in to the gateway "ftpgateway_username ftpgateway_password"
- then entering the command "quote site www.destination.com"
- then logging into the destination machine "user destination_username destination_password"
- turning off passive mode "passive"
- then transferring the file "put file"

How can I do this in Perl? I've got the following:
my $ftp; if ($ftp = Net::FTP->new("ftpgateway.mycompany.com", Debug => '1', Passive => '0')) { print "Connected.\n"; } else { print "Couldn't connect.\n"; exit; } if ($ftp->login("ftpgateway_username", "ftpgateway_password")) { print "Login sucessful\n"; } else { print "Login failed.\n"; exit; } if ($ftp->site("www.destination.com")) { print "opened www.destination.com.\n"; } else { print "Couldn't open destination.com.\n"; exit; } if ($ftp->quot("user destination_username destination_password")) { print "Logged into desination.com.\n"; } else { print "Couldn't log into destination.com.\n"; exit; } if ($ftp->put("file1.txt")) { print "Put file1.txt\n"; } else { print "Couldn't put file1.txt.\n"; exit; }
I get logged in ok, but when I try to the put command I get the error :
Net:FTP=GLOB(0x819dd68)<<< ftp: setsockopt (reuse addresss) Invalid ar +gument
What's going wrong?
Andrew

Replies are listed 'Best First'.
Re: FTP behind a gateway
by Thelonius (Priest) on Nov 01, 2002 at 17:13 UTC
    When you are typing "PASSIVE" in your command-line client, you are probably turning passive ON, not OFF. Passive generally works with firewalls. So try your code with Passive => 1.

    Besides that, there is an easier way. There is already code in Net::FTP to handle proxies. You need to add some code to your libnet.cfg file (typically in the Net/ directory, but there are ways of making user-local copies). See perldoc Net::Config. My Net/libnet.cfg looks like this:

    { ftp_firewall => 'corpgate03', ftp_firewall_type => 1, ftp_ext_passive => 1, local_netmask => [ "162.134.0.0/16", "172.24.0.0/16", "192.168.0.0/16", ], }
      I've worked out the problem, in case anyone's interested - instead of...
      $ftp->quot("user destination_username destination_password")
      ...do this...
      $ftp->login("destination_username", "destination_password")
      This will then allow you to ftp through a type 3 firewall (see perldoc Net::Config for definition of a type 3 firewall).

      I suppose this was a bit obvious though...

      Andrew