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

Monks, Can I use Perl to upload my script's output directly to an ftp server, without writing the output first to a file? It is a plain text file which I wish to create on the ftp server. Thanks for your consideration!
  • Comment on FTP with no intermediate file, to upload my program output?

Replies are listed 'Best First'.
Re: FTP with no intermediate file, to upload my program output?
by jZed (Prior) on Mar 23, 2005 at 23:48 UTC
    I'm unclear why that would be a good thing to do, but Net::FTP could do it. So can emacs (you can edit a file on a remote FTP server without creating a local copy).
Re: FTP with no intermediate file, to upload my program output?
by Joost (Canon) on Mar 23, 2005 at 23:55 UTC
      Touché. Here is what I have after checking on Net::FTP. My problem now is in going from $myfile to MYFILEHANDLE.
      Use Net::FTP; $myfile = "Two lines\n of text"; $ftp = Net::FTP->new("ftp.myhost.com", Debug => 0); $ftp->login('user','pass'); $ftp->cwd("/example"); $ftp->put(MYFILEHANDLE,filename.txt); $ftp->quit;
      Thanks again!

        Pre-perl5.8: check out IO::String.

        Perl5.8+: you can still use IO::String, but you can also do this:

        open my $fh, '<', \$myfile; $ftp->put($fh, 'filename.txt');