Dear monks

want to generate a temporary file (html) on a Windows desktop and upload it to a FTP server. I am succesfull in both single operations, but I have a problem if I combine them. This is my script:

use Net::FTP; use File::Temp qw(tempfile); #Creating my html in temporary file my $temp = new File::Temp( UNLINK => 1, SUFFIX => '.html' ); open (OUT, ">$temp") || (die "Can't open $temp\n"); binmode(OUT, ":utf8"); print OUT "My file content"; close (OUT); #uploading temporary html file to server my ($ftp, $host, $user, $pass, $dir); $host = "ftp.example.com"; $user = "myusername"; $pass = "hunter2"; $dir = "interpretbank.com/UserGlossary/"; $ftp = Net::FTP->new($host, Debug => 0); $ftp->login($user, $pass) || die $ftp->message; $ftp->cwd($dir); $ftp->put($temp) || die $ftp->message; $ftp->quit; print $ftp->message; #system("start file://$temp"); #just for check, open the temporary htm +l file in local browser $temp->seek( 0, SEEK_END );

Temporary file is generated fine, but when I upload it I get the following error message: Tk::Error: Must specify remote filename with stream input at $ftp->put($temp). A couple of considerations: if I run the two parts of the script (file generation and upload) separately (but preventing the temporary file to be deleted) I can upload my file. If a use system("start file://$temp"); to test the generated file, it is displayed in the Browser without problems, which should mean the temporary file is there when I try to upload it. What am I missing?


In reply to Generate temporary file and FTP upload by Anonymous Monk

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.