#!usr/bin/perl use strict; use warnings; use Fcntl qw( SEEK_END ); use File::Temp qw( tempfile ); #Creating a temporary html file in /tmp dir my $tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.html' ); print $tmp "Some data\n"; print "Filename is $tmp\n"; $tmp->seek( 0, SEEK_END ); __END__ $ perl test.pl Filename is /tmp/VlCSL2Fs39.html $ cat /tmp/VlCSL2Fs39.html Some data #### Filename is /tmp/grb8bazGjM.html unable to infer remote file name when a file handler is passed as local at test.pl line 31. #### #!usr/bin/perl use say; use strict; use warnings; use Net::SFTP::Foreign; my $htmlString = "

My First Heading

My first paragraph.

"; my $file = 'test.html'; #Creating an html file open my $fh, ">", $file or die "Can't open $file: $!"; say $fh $htmlString; close $fh or warn "Can't close $file: $!"; my %args = ( host => "localhost", user => "user", port => "22", # psw => "psw", # uncomment if you are using passwords key_path => "/home/user/.ssh/id_rsa" ); # comment if you are using passwords my $sftp = Net::SFTP::Foreign->new(%args); $sftp->die_on_error("Unable to establish SFTP connection"); my $path = '/path/path'; $sftp->setcwd($path) or die "unable to change cwd: " . $sftp->error; $sftp->put($file) or die "put failed: " . $sftp->error; unlink $file or warn "Could not unlink $file: $!"; __END__ $ perl test.pl $ cat /tmp/test.html

My First Heading

My first paragraph.

##
## #!usr/bin/perl use say; use strict; use warnings; use Net::SFTP::Foreign; use Fcntl qw( SEEK_END ); use File::Temp qw( tempfile ); #Creating a temporary html file in /tmp dir my $fh = File::Temp->new( UNLINK => 1, SUFFIX => '.html' ); say $fh "Some data"; say "Filename is $fh"; $fh->seek( 0, SEEK_END ); my $file = $fh->filename; my %args = ( host => "localhost", user => "user", port => "22", # psw => "psw", key_path => "/home/user/.ssh/id_rsa" ); my $sftp = Net::SFTP::Foreign->new(%args); $sftp->die_on_error("Unable to establish SFTP connection"); my $path = '/path/path'; $sftp->setcwd($path) or die "unable to change cwd: " . $sftp->error; $sftp->put($file) or die "put failed: " . $sftp->error;