For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2005 > Feed Net::FTP an in-memory file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Feed Net::FTP an in-memory file
Peter Rabbitson

2005-04-21, 3:56 pm

Hello everyone,

Very simple: I need to generate a file and upload it to ftp. Currently I am
wrapping the file together, writing it out to a temp file on disk,
calling $ftp->put($tmp_file) on it, and unlinking it. Is there a way to skip
the write to disk? The put() method seems to expect a path only, rather than
a filehandle....

Thanks
mgoland@optonline.net

2005-04-21, 3:56 pm



----- Original Message -----
From: Peter Rabbitson <rabbit@rabbit.us>
Date: Thursday, April 21, 2005 10:42 am
Subject: Feed Net::FTP an in-memory file

> Hello everyone,
>
> Very simple: I need to generate a file and upload it to ftp.
> Currently I am
> wrapping the file together, writing it out to a temp file on disk,
> calling $ftp->put($tmp_file) on it, and unlinking it. Is there a
> way to skip
> the write to disk? The put() method seems to expect a path only,
> rather than
> a filehandle....

One thing you can try is File::System::Real module. I have personaly never used it, but it sounds promising.
HTH,
Mark G.


>
> Thanks
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>


JupiterHost.Net

2005-04-21, 3:56 pm



Peter Rabbitson wrote:

> Hello everyone,


Hello,

> Very simple: I need to generate a file and upload it to ftp. Currently I am
> wrapping the file together, writing it out to a temp file on disk,
> calling $ftp->put($tmp_file) on it, and unlinking it. Is there a way to skip
> the write to disk? The put() method seems to expect a path only, rather than


You'd use stor/write/close:

my $stor = $ftp->stor($new_file_on_ftp_server);
$stor->write($new_file_guts, length($new_file_guts));
$stor->close();

See `perldoc Net::FTP` for more info

HTH :)

Lee.M - JupiterHost.Net
Peter Rabbitson

2005-04-21, 3:56 pm

On Thu, Apr 21, 2005 at 10:56:16AM -0500, JupiterHost.Net wrote:
>
>
> Peter Rabbitson wrote:
>
>
> Hello,
>
>
> You'd use stor/write/close:
>
> my $stor = $ftp->stor($new_file_on_ftp_server);
> $stor->write($new_file_guts, length($new_file_guts));
> $stor->close();
>
> See `perldoc Net::FTP` for more info
>
> HTH :)
>
> Lee.M - JupiterHost.Net
>


Errrr... This looks a little complicated. I mean I would have to get size of
the string in question and the data is utf8, meaning more headaches. Or I
simply don't know how to do it which leads to the same result :)

Nevertheless I somehow overlooked the part in the documentation where it
says that put() takes a filehandle as well:

open (VIRTUAL, '<:utf8', \$data);
$ftp->put (\*VIRTUAL, $conf->{target_tsv}) or die 'Could not upload file'
$ftp->quit;
close (VIRTUAL);

Works like a charm.

Thanks!

Peter


John W. Krahn

2005-04-21, 8:55 pm

Peter Rabbitson wrote:
> Hello everyone,


Hello,

> Very simple: I need to generate a file and upload it to ftp. Currently I am
> wrapping the file together, writing it out to a temp file on disk,
> calling $ftp->put($tmp_file) on it, and unlinking it. Is there a way to skip
> the write to disk?


FTP is the _File_ Transfer Protocol.

> The put() method seems to expect a path only, rather than
> a filehandle....


perldoc Net::FTP
[snip]
put ( LOCAL_FILE [, REMOTE_FILE ] )
Put a file on the remote server. "LOCAL_FILE" may be a name or a
filehandle.



John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com