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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |