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

I have a simple script that uses Net::FTP to open an FTP connection, like so:
$ftp = Net::FTP->new($FTP_HOST); $ftp->login($FTP_USERNAME, $FTP_PASSWORD);

I want the script to either continue running in the background (to keep the ftp connection alive) or exit without closing the connection.

Here's my real question:
I want to invoke a DIFFERENT perl script that will access the FTP object created in the first script, to utilize the put method of it.

(that way the 2nd script can quickly send the file without having to initialize the connection, as that was done in the first script)

I suppose I'm looking for a way to serialize the ftp object to a file, unless there is a better technique of interprocess communication that I can try.

Ideas anyone?

Replies are listed 'Best First'.
Re: How to serialize Net::FTP object?
by Joost (Canon) on Dec 06, 2004 at 20:38 UTC
    It's very likely impossible to serialize a Net::FTP object.

    There is an easier solution for your problem, though. Put the code that uses the FTP object in a subroutine (in a module, or in the same file as the code that creates the object) and call that sub.

    If that's impossible (because of the structure of the other script), you can put the object in a global and do the script.

      Thanks for your reply. The problem is since the first script creates the FTP object, and the other script (which uses the FTP object) would be invoked by an external process, there is no way to merge the 2 scripts. It would be 2 separate invocations, unless there is a way for the 2nd script to send a message to the first script.

      Here is my application: I want my text editor to invoke a program to ftp a file to a remote host when I need it to, but I want the ftp connection to already be open so that the text editor only needs to send the file, instead of initializing the connection each time. Ideas?

        You can't pass the FTP object in any meaningful way. Your only option is to run a perl server locally that maintains the ftp connect and listens for some other type of connections. Then your text editor can talk to that server and that server can use the ftp connection. It will be faster than opening a ftp connection every time, mostly.