Is there a way to extend Net::FTP so that it uses IO::Socket::SSL instead of IO::Socket::INET as its base class?
You can subclass Net::FTP and override its port method to do what you want.

port() currently does the following:

sub port { @_ == 1 || @_ == 2 or croak 'usage: $ftp->port([PORT])'; my ($ftp, $port) = @_; my $ok; delete ${*$ftp}{'net_ftp_intern_port'}; unless (defined $port) { # create a Listen socket at same address as the command socket ${*$ftp}{'net_ftp_listen'} ||= IO::Socket::INET->new( Listen => 5, Proto => 'tcp', Timeout => $ftp->timeout, LocalAddr => $ftp->sockhost, ); my $listen = ${*$ftp}{'net_ftp_listen'}; my ($myport, @myaddr) = ($listen->sockport, split(/\./, $listen->sockhost)); $port = join(',', @myaddr, $myport >> 8, $myport & 0xff); ${*$ftp}{'net_ftp_intern_port'} = 1; } $ok = $ftp->_PORT($port); ${*$ftp}{'net_ftp_port'} = $port; $ok; }

In your subclass, implement port() so that it does everything exactly the same, but call IO::Socket::SSL->new() instead.

Update: Hmmm, actually that'll just SSLify the reverse connection back to the client (which won't even work because the server won't be expecting it ;).

You might be able to do something like:

BEGIN { use Net::FTP; use IO::Socket::SSL; @Net::FTP::ISA = grep { $_ ne 'IO::Socket::INET' } @Net::FTP::ISA; push @Net::FTP::ISA, 'IO::Socket::SSL'; } my $ftp = Net:FTP->new(...); #etc

-David


In reply to Re: Extending Code By Changing the Base Class of an Object by erroneousBollock
in thread Extending Code By Changing the Base Class of an Object by cbeber

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.