Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does NET::FTP upload files so slowly

Tags:

perl

ftp

My problem is about using perl to ftp a local file to the ftp server. The question is why the upload speed is so slow. Here is code:

use strict;
use warning;

use NET::FTP;

my $ftpserver = "10.110.143.9";
my $usr       = "John";
my $passwd    = "John";

sub main {
    my $ftp = Net::FTP->new( $ftpserver, Timeout => 200 ) or print "Can't connect ftpserver" sleep 5;
    my $rc = $ftp->login( $usr, $passwd );
    unless ($rc) {
        print("login failed!");
        return 1;
    }
    print("login success");
    $ftp->binary();
    $ftp->put("d:\\2012.txt");
    $ftp->quit;
    return 0;
}

Upload times for 30mb are about 5 minutes while using another ftp client on the same machine takes only 10 seconds or so.

like image 442
John Avatar asked Jan 16 '13 01:01

John


1 Answers

You should enable PassiveMode, and also play with BlockSize (it used to be a source for slowdown with Net::FTP), something like this:

my $ftp = new Net::FTP(
    $ftpserver,
    Timeout => 200,
    Passive => 1,
    BlockSize => 8192,
);

Try increasing (or decreasing) BlockSize by factor of 2 few times and see if it changes anything.

like image 191
mvp Avatar answered Oct 21 '22 15:10

mvp