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

I have been having problems with using scp in the Net::SSH2 module. I can get sftp to work, but would really like to use ssh2->scp_??? to work.
When I executed a small program, I get:
-22LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED

I also tried using WinSCP to see if it was something on my end. I can connect with SFTP, but when I try using SCP, I get:
Connection has been unexpectedly closed.  Server sent command exit status 0
Error skipping startup message. Your shell is probably incompatible with the application (BASH is recommended).

I also tried using a different server and got the following error for scp using WinSCP:
Server refused to start a shell/command. Authentication log (see session log for details): Using username "myUserName". Authentication failed.


Can anyone help? Do I need to have the people at the server end configure SCP properly?? Is it something on my end?? Can I specify what type of shell to use??? Thanks for the help (if any)!

Replies are listed 'Best First'.
Re: ssh2 scp question
by jethro (Monsignor) on Nov 12, 2008 at 21:10 UTC

    The second error seems to indicate that you tried to connect to the other server with the username "MyUserName" instead of something like "john" or "Theodor".

    Since you didn't post your code it is nearly impossible for us to find out if the bug is in your or the modules code.

      This is my test script for trying to get/put files using ssh2->scp_???

      use strict; use warnings; use Net::SSH2; my $host = 'ftp.?????.com'; my $user = 'user'; my $password = 'password'; 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 get\n"; $ssh2->scp_get("test/out/MyFile-03.txt") or die ssh2->error; $ssh2->disconnect();


      I also used the opensource WinSCP to test out the connections and got errors when trying to use scp.
        Using your script on my Win32 box to connect to an SSH2 server on my linux box, I find that the connection is made without any trouble at all.
        However, the 'scp_get' call segfaults, and I get the following error message:
        libssh2_scp_recv(ss->session, path, &st) -> 0x2b849a4
        If I try an 'scp_put' I get a similar message (and segfault):
        libssh2_scp_send_ex(ss->session, path, mode, size, mtime, atime) -> 0x +2b8a0d4
        I find that the file I tried to upload with 'scp_get' was created in the correct location on the server ... but is empty :-(
        The test script that ships with the Net-SSH2 source, constructs the 'scp_get' call a little differently (though that's not the problem, afaict). It does:
        my $check = IO::Scalar->new; $ssh2->scp_get($remote, $check);
        I hadn't realised scp wasn't working on Windows. (I failed to notice that, since IO::Scalar was not installed, the scp tests were being skipped.) OTOH, sftp seems to work fine
        I'm using Net-SSH2-0.18 on perl-5.10.

        Update: Just noticed that 'scp_put' and 'scp_get' both work ok for me on perl-5.8.8, Win32. If you're using Win32, and you really do need scp, then 5.8.8 is probably the simplest way to achieve it.

        Cheers,
        Rob