I use the net :: SSH2 scp_put method to place a single file in my home directory on a Unix server from a Windows window. I am using Strawberry Perl 5.12 (portable version). I installed the libssh2 1.2.5 binaries and then Net :: SSH2 from cpan.
Here is my code snippet:
sub uploadToHost{
my $file=@_[0];
my $host=@_[1];
my $user=@_[2];
my $pass=@_[3];
my $remotelocation=@_[4];
my $ssh=Net::SSH2->new() or die "couldn't make SSH object\n";
$ssh->debug(1);
$ssh->blocking(1);
print "made SSH object\n";
$ssh->connect($host) or die "couldn't connect to host\n";
print "connected to host\n";
$ssh->auth_password($user, $pass) or die "couldn't authenticate $user\n";
print "authenticated $user\n";
$ssh->scp_put($file, $remotelocation") or die "couldn't put file in $remotelocation\n";
print "uploaded $file successfully\n";
$ssh->disconnect or die "couldn't disconnect\n";
} #ends sub
Output (edited for anonymity):
created an SSH object \ n
connected to host \ n
authenticated \ n
libssh2_scp_send_ex (ss-> session, path, mode, size, mtime, atime) → 0x377e61c \ n
Net :: SSH2 :: Channel :: read (size = 1, ext = 0) \ n
Then it hangs forever (> 40 minutes in one test) and needs to be killed.
, scp ! , . StackOverflow .
- : 1) 2) ( ) , , scp ?
, !