Marshall Dudley said:
Is there any way to send a variable via ftp with perl? I am trying to
use NET::FTP, but I cannot find any way to tell it to send the data to
the other end. All I can find is to send a file from the hard drive to
the remote, but the data is not in a file, but created by the script
that is attempting to send it and in a simply text variable
Did you read this paragraph?
put ( LOCAL_FILE [, REMOTE_FILE ] )
Put a file on the remote server. "LOCAL_FILE" may be a name or a
filehandle. If "LOCAL_FILE" is a filehandle then "REMOTE_FILE"
must be specified. If "REMOTE_FILE" is not specified then the file
will be stored in the current directory with the same leafname as
"LOCAL_FILE".
The local file doesn't have to be on the hard drive, you can specify
a file handle. Then the data could come from anywhere, for instance
from print statements in your code.
I don't think that FTP is the right tool for what you want to do,
but just for fun, here is how it *could* be done:
You have one problem: The call to ->put only returns after the
transfer is finished, so you don't get a chance to print the data
in the same process that runs ->put. You'll need to fork another
process for that and use a pipe to communicate between the two.
use Net::FTP;
my $ftp = Net::FTP->new( 'host') or die 'new';
$ftp->login( 'user', 'password') or die 'login';
pipe( my ( $r, $w)) or die 'pipe';
if ( my $pid = fork ) {
defined( $pid) or die 'fork';
close $r;
print $w "$_\n" for qw( hihi haha hoho);
} else {
close $w;
$ftp->put( $r, '/remote/file') or die 'put';
}
Anno