wet has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have an issue with Net::SSH2 between windows and Linux file transfers, where the program abends on initiating a file transfer and the file name contains an apostrophe (single quote "'") from windows to linux, but not the otherway around nor from Linux to Linux or BSD (or vice versa).

In other words the filename has a single quote on the windows host (why someone would do this is another thing, but it happens) ansd does not seem to be an issue with other character "()[]{}@#$%!" etc

with the debug option on, ssh2 reports the following

libssh2_scp_recv(ss->session, path, &st) -> 0x0 SSH Error (-28): LIBSSH2_ERROR_SCP_PROTOCOL - Failed to recv file

of course the program abend is part of the script and is triggered by the above failure.

a little more digging beyond the obvious perl issues such as parameter passing and string character escapes within the script and SSH2 mperl modules highlights the following

root@slack-one:/usr/local/lib/perl5# grep -R libssh2_scp_recv ./
Binary file ./auto/Net/SSH2/SSH2.so matches
root@slack-one:/usr/local/lib/perl5#

which is now a binary object created by the module make maker, as for the issue, I am assuming that the filename string breaks somewhere between the SSH2 lib and the perl interface, having no experience beyond installing these things from the cpan or other sources, my question would be where would I look into this or at least pass some pointers, clues or rfrences to any documentation that could be helpful in determining the problem.

in the interem i have resolved the issue by renaming the source file on windows from within the Linux perl script transfering the file and then renaming it once more, but it is an ugly solution ...


regards
  • Comment on >Windows filename troubles with Net::SSH2

Replies are listed 'Best First'.
Re: >Windows filename troubles with Net::SSH2
by syphilis (Archbishop) on Aug 12, 2013 at 12:55 UTC
    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
      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...