#!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.