use strict; use warnings; use File::Temp 'tempfile'; use Net::FTP; use constant HOSTNAME => 'ftp.example.com'; use constant USERNAME => 'grinder'; use constant PASSWORD => 'seekret'; my $msg = ; my ($out, $file) = tempfile('msg_XXXXXXXX', SUFFIX => '.txt'); print $out $msg or die "Cannot print to $file: $!\n"; close $out or die "Cannot close $file: $!\n"; my $host = Net::FTP->new(HOSTNAME) or die "Cannot connect to ", HOSTNAME, ": $!\n"; $host->login(USERNAME, PASSWORD) or die "login error: ", $host->message, $/; $host->put($file) or die "cannot put $file: ", $host->message, $/; $host->quit; unlink $file;