I'm not familiar with Net::SFTP, but a quick read seems that it doesn't support passing a socket object, which is how modules like Net::Telnet (which as of 3.04, supports IPv6) and Net::SSH2 allowed for IPv6 support. I use Net::SSH2 because it's the only SSH module I was able to get to work on Windows - comes bundled with Strawberry Perl in vendor/lib.

It goes something like this (following code passes 'perl -c'):

#!perl use strict; use warnings; use Getopt::Long qw(:config no_ignore_case); use Socket qw(inet_ntoa AF_INET IPPROTO_TCP); use Net::SSH2; # Conditional use of IO::Socket::IP, older than 5.16 doesn't have by d +efault my $HAVE_IO_Socket_IP = 0; eval "use IO::Socket::IP -register"; if(!$@) { $HAVE_IO_Socket_IP = 1 } else { eval "use IO::Socket::INET" } # Backward compatible, older versions of Socket don't have AF_INET6 my $AF_INET6 = eval { Socket::AF_INET6() }; # Get command line options for IPv4 or IPv6 and host my %opt; GetOptions( '4!' => sub { $opt{family} = AF_INET}, '6!' => sub { $opt{family} = $AF_INET6}, 'host' => $opt{host}, ); # If IPv6 and we don't have IO::Socket::IP, fail if (!$HAVE_IO_Socket_IP && defined $opt{family} && ($opt{family} == $A +F_INET6)) { print "$0: IO::Socket::IP required for IPv6\n"; exit 1 } # Default to IPv4 for backward compatiblity - THIS MAY CHANGE IN THE F +UTURE!!! if (!defined $opt{family}) { $opt{family} = AF_INET } # Open socket my $socket; if ($HAVE_IO_Socket_IP) { $socket = IO::Socket::IP->new( PeerHost => $opt{host}, PeerPort => 22, Family => $opt{family}, ) } else { $socket = IO::Socket::INET->new( PeerHost => $opt{host}, PeerPort => 22, ) } # Open Net::SSH2 connection with the IO::Socket::IP object my $ssh2 = Net::SSH2->new(); if ($ssh2->connect($socket)) { print "[Connected]\n"; # DO STUFF } else { warn "Unable to connect to host $opt{host}: $!\n" }

In reply to Re: Enhancing Net::SFTP (& Net::SSH) to support IPv6 by VinsWorldcom
in thread Enhancing Net::SFTP (& Net::SSH) to support IPv6 by albus123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.