I was searching through the categorize Q&A, and mccormi asked a question that was a problem i had given up on a while back.
I'm not sure whether the problem is related to my ignorance or the module, but here's what i've discovered:

Net::FTP doesn't support any sort of variable uploads, just named files, and filehandles.
With the objective being to upload without using a file on the network, (useful for me, for example, when i want to upload a zipped (tgz'd) backup of a filesystem, too large to write to disk first), my first line of thought was "hmm... it takes filehandles, see if STDIN works"... and it does:

$ftp = Net::FTP->new($destserv) || die "error connecting\n"; $ftp->login($destuser,$destpass); $ftp->binary(); $ftp->put(*STDIN,$remotefile) or die "error uploading\n"; $ftp->quit();

This will solve the issue at hand, by allowing a first script to pipe data into the STDIN of this script, to upload data without a file. However, I don't see why this has to be written with two processes. So, my second line of thought was "hmmm... it takes filehandles, use tie"... So, using IO::Scalar I wrote this:

my $data="FOOBAR"; tie *FOO, 'IO::Scalar',\$data; $ftp = Net::FTP->new($destserv) || die "error connecting\n"; $ftp->login($destuser,$destpass); $ftp->binary(); $ftp->put(*FOO,"remotelogfile") or die "error uploading\n"; $ftp->quit();

and while this scalar works for me as a FILE with normal filehandle usage,

while (<FOO>){print $_;} print FOO "hi";

in this particular module, i get the following error:

Cannot open Local file *main::FOO: No such file or directory at ./netftpcgi.pl line 18
error uploading

This leads me to believe that for some reason, *main::FOO is different than *main::STDIN and that Net::FTP can tell. If anyone would help me with my logic, I'd appreciate it.


In reply to Inconsistancy within Net::FTP? by vaevictus

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.