It needs both Net::SSH2 and Net::SFTP::Foreign.use warnings; use strict; use Net::SFTP::Foreign; my $host = 'xxx.xxx.xxx.xxx'; my $user = 'user'; my $pass = 'pass'; my $file = 'whatever'; my $contents; my $sftp = Net::SFTP::Foreign->new ($host, backend => 'Net_SSH2', username => $user, password => $pass); $sftp->error and die "Unable to establish SFTP connection: " . $sftp->error; $sftp->get($file, "foo.txt") or die "get failed: " . $sftp->error; open RD, '<', "foo.txt" or die $!; while (<RD>) {$contents .= $_} close RD or die "$!"; print $contents; unlink "foo.txt";
use warnings; use strict; use Net::SFTP::Foreign; my $host = 'xxx.xxx.xxx.xxx'; my $user = 'user'; my $pass = 'pass'; my $file = 'whatever'; my $contents; my $sftp = Net::SFTP::Foreign->new ($host, backend => 'Net_SSH2', username => $user, password => $pass); $sftp->error and die "Unable to establish SFTP connection: " . $sftp->error; close STDOUT; open STDOUT, '>', \$contents or die "Can't open STDOUT: $!"; $sftp->get($file, \*STDOUT) or die "get failed: " . $sftp->error; warn $contents;
In reply to Re: Windoze:SFtp into a scalar
by syphilis
in thread Windoze:SFtp into a scalar
by NateTut
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |