Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Extending Code By Changing the Base Class of an Object

by erroneousBollock (Curate)
on Sep 11, 2007 at 16:13 UTC ( #638347=note: print w/replies, xml ) Need Help??

in reply to Extending Code By Changing the Base Class of an Object

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


Replies are listed 'Best First'.
Re^2: Extending Code By Changing the Base Class of an Object
by cbeber (Initiate) on Sep 11, 2007 at 16:45 UTC
    I appriciate the help. I'll play with the BEGIN block and see if I can get it to work that way.

    I'll post results if/when I can get this up and running.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://638347]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2023-09-22 01:52 GMT
Find Nodes?
    Voting Booth?

    No recent polls found