## scp.pl ##
use strict;
use warnings;
use Net::SSH2;
die "Usage: perl scp.pl host username password"
unless @ARGV == 3;
my $host = $ARGV[0];
my $user = $ARGV[1];
my $password = $ARGV[2];
my $ssh2 = Net::SSH2->new();
$ssh2->debug(1);
print "\nconnecting to $host...\n";
$ssh2->connect($host) or die $ssh2->error;
print "\nauth to $host...\n";
$ssh2->auth_password($user,$password) or die $ssh2->error;
printf "Auth OK: %s\n", $ssh2->auth_ok;
print "scp put\n";
my $ret = $ssh2->scp_put("rub'bish.txt", "rub'bish.txt");
print "ret: $ret\n";
$ssh2->disconnect();
###
print("...\n\n");
$ssh2=undef;
$ssh2=Net::SSH2->new();
$ssh2->debug(1);
$ssh2->connect($host) or die $ssh2->error;
$ssh2->auth_password($user,$password) or die $ssh2->error;
$ssh2->scp_get("rub'bish.txt", "more-rub'bish.txt");
printf("SSH Error (%s): '%s' - '%s'\n",$ssh2->error);
$ssh2->disconnect();
print("...\n\n");
$ssh2=undef;
$ssh2=Net::SSH2->new();
$ssh2->debug(1);
$ssh2->connect($host) or die $ssh2->error;
$ssh2->auth_password($user,$password) or die $ssh2->error;
$ret=$ssh2->scp_get("06 School's Out.mp3", "06 School's Out.mp3");
printf("SSH Error (%s): '%s' - '%s'\n",$ssh2->error);
$ssh2->disconnect();
####
wet@slack-one:~$ echo '3 blind mice, girls in a tub' > "rub'bish.txt"
wet@slack-one:~$ perl scp-t.pl snoopy wet wetwipe
connecting to snoopy...
auth to snoopy...
Auth OK: 1
scp put
libssh2_scp_send_ex(ss->session, path, mode, size, mtime, atime) -> 0x87123a0
Net::SSH2::Channel::read(size = 1, ext = 0)
- read 1 bytes
- read 1 total
Net::SSH2::Channel::DESTROY
ret: 1
...
Net::SSH2::DESTROY object 0x870a3e8
Net::SSH2: created new object 0x870a3e8
libssh2_scp_recv(ss->session, path, &st) -> 0x87123a0
Net::SSH2::Channel::read(size = 29, ext = 0)
- read 29 bytes
- read 29 total
Net::SSH2::Channel::read(size = 1, ext = 0)
- read 1 bytes
- read 1 total
Net::SSH2::Channel::DESTROY
SSH Error (0): '' - ''
...
Net::SSH2::DESTROY object 0x870a3e8
Net::SSH2: created new object 0x870a3e8
libssh2_scp_recv(ss->session, path, &st) -> 0x0
SSH Error (-28): 'LIBSSH2_ERROR_SCP_PROTOCOL' - 'Failed to recv file'
Net::SSH2::DESTROY object 0x870a3e8
wet@slack-one:~$
wet@slack-one:~$ ls -la
total 24
drwx--x--x 2 wet users 4096 Aug 12 14:38 ./
drwxr-xr-x 7 root root 4096 Aug 12 13:46 ../
-rw-r--r-- 1 wet users 3729 Jul 18 2011 .screenrc
-rw-r--r-- 1 wet users 29 Aug 12 14:37 more-rub'bish.txt
-rw-r--r-- 1 wet users 29 Aug 12 14:37 rub'bish.txt
-rw-r--r-- 1 wet users 1260 Aug 12 14:37 scp-t.pl
wet@slack-one:~$
##
##
C:\netupfiles\home\wet>dir
Volume in drive C is Polly
Volume Serial Number is D00B-FC85
Directory of C:\netupfiles\home\wet
2013/08/12 04:36 PM .
2013/08/12 04:36 PM ..
2013/08/12 04:10 PM 29 'rub'''bish.txt'
2006/12/20 12:46 AM 8 427 472 06 School's Out.mp3
2 File(s) 8 427 501 bytes
2 Dir(s) 160 523 104 256 bytes free
C:\netupfiles\home\wet>