Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: >Windows filename troubles with Net::SSH2

by syphilis (Canon)
on Aug 12, 2013 at 12:55 UTC ( #1049115=note: print w/ replies, xml ) Need Help??


in reply to >Windows filename troubles with Net::SSH2

If I understand correctly, the SSH server is running on Windows and the transfer script (which is running on Linux) obtains the file from the Windows machine using scp_get().
This could mean that the problem is with the SSH server on the Windows machine, and nothing to do with perl at all.
A small example script that demonstrates the problem might help.

I couldn't find any such problem when using a Net::SSH2 script (run on my Windows machine) to scp_put() the file onto my Linux machine. I ran this:

## scp.pl ## use strict; use warnings; use Net::SSH2; die "Usage: perl scp.pl username password" unless @ARGV == 2; my $host = '192.168.0.101'; my $user = $ARGV[0]; my $password = $ARGV[1]; 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", "/home/sisyphus/Downloads/rub'bish.txt"); print "ret: $ret\n"; $ssh2->disconnect();
It transferred rub'bish.txt from the windows machine to the Linux machine just fine.
Unfortunately my Windows machine doesn't have an SSH server so I can't try doing it the "other" way.

Cheers,
Rob


Comment on Re: >Windows filename troubles with Net::SSH2
Select or Download Code
Re^2: >Windows filename troubles with Net::SSH2
by wet (Initiate) on Aug 12, 2013 at 15:20 UTC
    thats correct the windows machine is running an ssh server, I had setup a widows test environment and ran your code on the linux end of this setup - and no issuesrunning your code on linux shows no issues. made some minor changes and to your code (listed below), and placed a copy of the file, that caused the issue initially, on the windows host to demonstrate the failure.
    ## 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();
    and the terminal out is
    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) -> 0x +87123a0 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:~$
    then checking out the windows directory listing, shock-horror-wtf, brings to light the obvious, there is some extra quoting going on somewhere. The original windows machine in question is a hub of sorts serving a number of clients (windows) who dont have this issue.
    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 <DIR> . 2013/08/12 04:36 PM <DIR> .. 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>
    thank you to syph... your response prompted me to some usefull action, making the problem a little clearer...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049115]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2015-07-06 12:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls