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

Hi,

I'm basically very new to Perl and I've gone through some of the examples pertaining to secure file copy from a windows based server to an Unix Based server. When using a small file (>10kb) to test the transfer it's successfull, however when the file is bigger (>300kb)the file gets copied partially before truncating and returning an error message. The error message is at the line of scp_put. Below is the script that I'm using.

use warnings; use strict; use Net::SSH2; my $server = "212.100.100.239"; my $datafile = "D:/ETL/RPT/MD/IMSI_SICAP.lst"; #my $datafile1 = "D:\\ETL\\RPT\\MD\\"; my $ssh2 = Net::SSH2->new; die "can't connect" unless $ssh2->connect($server); print "Connected\n"; die "can't authenticate" unless $ssh2->auth(username => 'user',password => 'aaa'); print "Authenticated\n"; my $sftp = $ssh2->sftp; $ssh2->debug(1); my $dir = "/timesten_old/IMSI_SICAP.lst"; $ssh2 ->scp_put("${datafile}","${dir}")or die ("Error"); print "Success\n"; $ssh2->disconnect();

Would really appreciate it if some one could guide me on what I'm doing wrong here. Thanks.

Replies are listed 'Best First'.
Re: Unable to transfer file with scp_put using Net::SSH2
by syphilis (Archbishop) on Aug 02, 2010 at 09:11 UTC
    when the file is bigger (>300kb)the file gets copied partially before truncating and returning an error message

    I find the same thing when I scp_put (~6Mb file) from Windows to a remote linux server ... but no problem when I scp_put the same file from the same Windows machine to my local linux box.
    I've therefore taken to blaming the server on the remote box, or the speed of the connection, but of course I don't really know what the problem is. Thankfully, if I keep trying long enough, the upload eventually succeeds. I've sometimes felt that it helps to unlink the truncated file from the remote server before re-attempting the scp_put.

    You can perhaps get a better idea of the error, by doing:
    if(!($ssh2 ->scp_put(${datafile},${dir}))) { my @error = $ssh2->error(); die ("@error"); }
    Can someone examine the server logs at the other end for any clue for you ? (In my case, I'm given access to the remote server as a favour, so am not keen to seek that sort of assistance.)

    Or maybe even the server could be put into debug mode for you ?

    Other than that, is uploading with sftp (again using Net::SSH2) an option for you ? I haven't yet tried that, but it's something I intend to try next time I strike trouble with scp_put.

    Finally, which version of perl are you running, which version of Net::SSH2 do you have, and how did you install it ? Tomorrow, I could upload the latest version of Net::SSH2, built against the latest libssh2 library to the uwinnipeg ppm repository, if you like. Not sure that it will fix the problem however ... didn't for me.

    Cheers,
    Rob
      That looks like a bug in Net::SSH2, you should report it!
      Hi Rob,

      Thanks very much for your feedback. I tried the code given by yourself to understand the error returned better, but still could not make sense of it, perhaps you could shed some light for me. Below are the error returned:

      D:\Test>call test_a.pl > samle.log libssh2_scp_send_ex(ss->session, path, mode, size, mtime, atime) -> 0x +1d05914 Net::SSH2::Channel::DESTROY -37 LIBSSH2_ERROR_EAGAIN Unable to send channel data at D:\Test\test_a +.pl line 26. Net::SSH2::SFTP::DESTROY Net::SSH2::SFTP::DESTROY freeing session Net::SSH2::DESTROY object 0x19b6b3c

      The perl version : v5.8.8 built for MSWin32-x86-multi-thread.

      Net::SSH2 version : 0.28

      Installed it via ppm and obtained the ppd file from http://theoryx5.uwinnipeg.ca/ppms/Net-SSH2.ppd.

      Please do let me know if you upload the latest version of Net::SSH2, at least i could still give it a try. Thanks again.

      Regards,

      Sandra

        Hi Sandra,
        Sorry - missed your reply. That's the same error as I was getting. This patch fixes the problem for me - and I think it will do the same for you.

        There's already a bug report filed about this. That bug report also specifies a second patch to SSH2.xs which I haven't applied, as I haven't yet struck a need for it - and there seems to be some doubt as to what is the correct fix.

        I'll /msg you (should be later today) when I've uploaded 0.33 ppm packages that include the above patch. Alternatively, you can just alter SSH2.pm in accordance with that patch - and that should work fine.

        Btw, I did find that sftp was quite capable of uploading these files that scp couldn't, though it was much slower.

        Cheers,
        Rob
Re: Unable to transfer file with scp_put using Net::SSH2
by Khen1950fx (Canon) on Aug 02, 2010 at 07:59 UTC
    Line 23 should be
    $ssh2->scp_put($datafile, $dir) or die "Error\n";
      Hi,

      Thanks for your feedback. When i changed line 23 as per your advice the result is still the, where it return the below error:

      D:\Test>call test_a.pl > samle.log libssh2_scp_send_ex(ss->session, path, mode, size, mtime, atime) -> 0x +1d049e4 Net::SSH2::Channel::DESTROY Error at D:\Test\test_a.pl line 23. Net::SSH2::SFTP::DESTROY Net::SSH2::SFTP::DESTROY freeing session Net::SSH2::DESTROY object 0x19c6e0c