So I'm trying to connect to our SFTP server via a Perl script using Net::OpenSSH and Net::SFTP::Foreign, but I've never worked with with these modules before, and I'm having trouble getting the script to actually put a file on my ftp server. My script is below.
#!/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 d +ie "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 "C +an't get\n" . $sftp->error; open SFILE, "/usr/local/nagios/Misc/test/sftptest" or die $!; while(<SFILE>){ chomp; $fileOut = $_; } print $fileOut; exit;
So what I don't understand is what do I pass into the sftp() method that ssh is calling? In the Net::OpenSSH documentation, it says %sftp_opts, but since I'm connecting using the SSH connection string, what goes there? Currently if I leave it blank I get the error "Can't call method "put" on an undefined value at /usr/local/nagios/Working/sftp_fresh.pl" Thanks for the help!
In reply to How to connect to SFTP via OpenSSH by Logic_Bomb421
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |