Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Generate temporary file and FTP upload
by poj (Abbot) on Jun 30, 2017 at 19:43 UTC | |
by karlgoethebier (Abbot) on Jun 30, 2017 at 21:00 UTC | |
by welleozean (Novice) on Jun 30, 2017 at 19:50 UTC | |
|
Re: Generate temporary file and FTP upload
by huck (Prior) on Jun 30, 2017 at 19:49 UTC | |
|
Re: Generate temporary file and FTP upload
by karlgoethebier (Abbot) on Jun 30, 2017 at 19:22 UTC | |
by welleozean (Novice) on Jun 30, 2017 at 19:29 UTC | |
by karlgoethebier (Abbot) on Jun 30, 2017 at 19:49 UTC | |
|
Re: Generate temporary file and FTP upload
by thanos1983 (Parson) on Jul 01, 2017 at 16:43 UTC | |
by salva (Canon) on Jul 03, 2017 at 07:53 UTC |