#!/usr/bin/perl use lib "PATH TO Net::OpenSSH libraries"; use Net::OpenSSH; use IO::Pty; use Net::SFTP::Foreign; use Time::Piece; $host = "SFTP ADDRESS"; $user = "SFTP USERNAME"; $pw = "SFTP PASSWORD"; $putFile = "/usr/local/nagios/Misc/sftptest"; $getFile = "sftptest"; $date = localtime->strftime('%m/%d/%Y %H:%M'); open SFILE, ">$putFile" or die $!; print SFILE "$date\n"; close (SFILE); $ssh = Net::OpenSSH->new(host=>$host, user=>$user, password=>$pw) or die "can't :(\n" . $ssh->error; $sftp = $ssh->sftp(); $sftp->put($putFile) or die "Can't put\n" . $sftp->error; $sftp->get($getFile, "/usr/local/nagios/Misc/test/sftptest") or die "Can't get\n" . $sftp->error; open SFILE, "/usr/local/nagios/Misc/test/sftptest" or die $!; while(){ chomp; $fileOut = $_; } print $fileOut; exit;