Logic_Bomb421 has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to connect to SFTP via OpenSSH
by tangent (Parson) on Aug 26, 2014 at 00:10 UTC | |
by Logic_Bomb421 (Novice) on Aug 26, 2014 at 00:25 UTC | |
by tangent (Parson) on Aug 26, 2014 at 01:24 UTC | |
by Logic_Bomb421 (Novice) on Aug 26, 2014 at 17:56 UTC | |
by salva (Canon) on Aug 26, 2014 at 18:10 UTC | |
| |
by tangent (Parson) on Aug 26, 2014 at 19:55 UTC | |
|
Re: How to connect to SFTP via OpenSSH
by salva (Canon) on Aug 26, 2014 at 07:02 UTC |