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

Hi,

how can I force Net::FTP->new(...) to use IPV4 ?

I know, I could use an IP-Address as host - but I would like to stay with a hostname!

I have activated IPV6 in my network and now this is used as a standard. In general this is fine. But for the connection I use it looks like IPV6 does not work.

To get it working until I have found the root cause on IPV6 I would like to force my script to use IPV4 only.

Regards Kallewirsch

Replies are listed 'Best First'.
Re: Net::FTP force IPV4
by hippo (Archbishop) on Jun 27, 2023 at 09:10 UTC

    Per the documentation:

    Domain - Domain to use, i.e. AF_INET or AF_INET6. This argument will be passed to the IO::Socket super class. This can be used to enforce IPv4 even with IO::Socket::IP which would default to IPv6. Family is accepted as alternative name for Domain.

    So, something like:

    my $ftp = Net::FTP->new ('ftp.foo.com', Domain => AF_INET);

    🦛

      I already tried this!

      Result: Bareword "AF_INET" not allowed while "strict subs" in use at

      Regards Kallewirsch

        You need to import AF_INET:

        use IO::Socket qw(AF_INET);
Re: Net::FTP force IPV4
by choroba (Cardinal) on Jun 27, 2023 at 09:17 UTC
    Not sure about Net::FTP, but most modules I've worked with respected the $IPV environment variable. So, before running your program (from a *nix box)
    export IPV=4
    could work. Or, to set the environment only for the program:
    IPV=4 /path/to/the/program

    The other possible values are 6 and *.

    Update: The variable is documented in Net::Server::Proto, so most probably not going to help with Net::FTP.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      My duckduckgofu is failing me; do you have a pointer to where this var is documented? Not doubting but just wondering where this happens (my hunch is it’s glibc magic but my searching is coming up blank).

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        Oh sorry, it seems to come from Net::Server::Proto, so it doesn't apply to Net::FTP.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]