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

Hello Monks,

I am using Net::SFTP::Foreign for downloading files form my remote server and experiencing highly slow performance. It is taking all most 10 times than WinSCP. I have installed Math-BigInt through ppm but didn't found any improvement. Please advise how to improve the performance or any other solution for SFTP. Thanks in advance.

Replies are listed 'Best First'.
Re: Net::SFTP::Foreign is slow
by syphilis (Archbishop) on Jul 11, 2011 at 23:28 UTC
      Thanks Rob for your help. I have installed "Net-SFTP-Foreign-Backend-Net_SSH2" and modified the code as below, but getting this error, please guide if I have done something wrong.
      use Net::SFTP::Foreign; my $sftp = Net::SFTP::Foreign->new( host => 'delivery.myserver.com', port => '22', backend => 'Net_SSH2', user => 'ftp_user', more => [qw(-i mytransaction.private.key.ppk)], ssh_cmd => 'plink'); $sftp->die_on_error("Unable to establish SFTP connection");
      error is "Invalid options 'ssh_cmd', 'more' or bad combination of options at sftp.pl line 2"
        syphilis is right, you can't use more or ssh_cmd with the Net_SSH2 backend.

        Do as follows:

        use Net::SFTP::Foreign 1.67; use Net::SFTP::Foreign::Backend::Net_SSH2 0.04; my $sftp = Net::SFTP::Foreign->new( host => 'delivery.myserver.com', port => '22', backend => 'Net_SSH2', user => 'ftp_user', key_path => "mytransaction.private +.key"); $sftp->die_on_error("Unable to establish SFTP connection");
        You will probably have to convert the private key from PuTTY to OpenSSH format and place the public key in the same directory with the .pub suffix.
        Invalid options 'ssh_cmd', 'more' or bad combination of options at sftp.pl line 2

        It may be that the 'more' and 'ssh_cmd' options don't work on Windows - I'm almost certain 'more' doesn't work. If salva drops by (as he usually does) he would be able to give you more definitive advice.
        I've only ever used this module for 'get', 'put', 'del', 'ls' and maybe a couple of other commands that I can't recall at the moment. For those purposes I've found it to be excellent.

        Cheers,
        Rob
Re: Net::SFTP::Foreign is slow
by runrig (Abbot) on Jul 11, 2011 at 22:56 UTC
    Net::SFTP::Foreign is a wrapper for doing sftp over command line ssh. Math-BigInt would not help there. You can also try Net-SSH2.
Re: Net::SFTP::Foreign is slow
by salva (Canon) on Jul 12, 2011 at 09:10 UTC
    Net::SFTP::Foreign on Windows uses a small pipeline (due to the lack of a proper select able to work in pipes), so, if your network has a relative high latency, it would perform poorly.

    Try incrementing the pipeline size as follows:

    $sftp = Net::SFTP::Foreign->new(..., queue_size => 32);
    If that doesn't improve the transfer speed, add...
    $Net::SFTP::Foreign::debug = 1|32|256;
    at the beginning of your script and post here the output or send it to me by email (I am the module author btw).

      Hi Salva, There is no improvement of adding the queue_size. I trust there is no issue with network as am able to download same file by WinSCP and performance is far better. I don't have your mail id so attaching some part of the debug message here

      #8788 1310498030.00000 got it!, len:32777, code:103, id:109, status: - #8788 1310498030.00000 queueing msg len: 25, code:5, id:141 ... [32] #8788 1310498030.00000 waiting for message... [32] #8788 1310498031.00000 got it!, len:32777, code:103, id:110, status: - #8788 1310498031.00000 queueing msg len: 25, code:5, id:142 ... [32] #8788 1310498031.00000 waiting for message... [32] #8788 1310498032.00000 got it!, len:32777, code:103, id:111, status: - #8788 1310498032.00000 queueing msg len: 25, code:5, id:143 ... [32] #8788 1310498032.00000 waiting for message... [32] #8788 1310498033.00000 got it!, len:32777, code:103, id:112, status: - #8788 1310498033.00000 queueing msg len: 25, code:5, id:144 ... [32] #8788 1310498033.00000 waiting for message... [32] #8788 1310498034.00000 got it!, len:32777, code:103, id:113, status: - #8788 1310498034.00000 queueing msg len: 25, code:5, id:145 ... [32] #8788 1310498034.00000 waiting for message... [32] #8788 1310498035.00000 got it!, len:32777, code:103, id:114, status: - #8788 1310498035.00000 queueing msg len: 25, code:5, id:146 ... [32] #8788 1310498035.00000 waiting for message... [32] #8788 1310498037.00000 got it!, len:32777, code:103, id:115, status: - #8788 1310498037.00000 queueing msg len: 25, code:5, id:147 ... [32] #8788 1310498037.00000 waiting for message... [32] #8788 1310498038.00000 got it!, len:32777, code:103, id:116, status: - #8788 1310498038.00000 queueing msg len: 25, code:5, id:148 ... [32]
        What version of the module were you using when you got this output?