use Net::FTP; use strict; #This works. It opens a in memory file first, passing it to a sub, and + do something. { my $in_mem; print "First try something else\n"; open(AFILE, ">", \$in_mem); write_okay_okay(*AFILE); close(AFILE); print $in_mem, "\n"; } #This does not work. It opens a in memory file, passing it to Net::FTP +->get(). #However got error msg complained bad file descriptor { print "Now try FTP with in mem\n"; my $ftp = new Net::FTP("Kyanite", Debug => 1); $ftp->login("user name", "password"); my $in_mem; open(BFILE, ">", \$in_mem) || die "failed"; print BFILE "okayokay"; $ftp->get("MComSubChng.txt", \*BFILE); $ftp->quit(); close(BFILE); print $in_mem, "\n"; } #This works fine. It opens a normal file, and pass the handler to Net: +:FTP->get(). #I checked, and the local file was created { print "Now try FTP norm\n"; my $ftp = new Net::FTP("Kyanite", Debug => 1); $ftp->login("user name", "password"); open(BFILE, ">", "bfile") || die "failed"; $ftp->get("MComSubChng.txt", \*BFILE); $ftp->quit(); close(BFILE); } sub write_okay_okay { my $file = shift; print $file "okay okay"; }
In reply to question about Net::FTP + in memory file handler by pg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |