Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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


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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2023-10-04 16:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found