Ftp slow

Hi All !
Who can explain me, why same code on ruby much more slow then same on perl
I need fetch reports for publication on WEB (Intranet)
ruby’s script do it by cron every day
sample code

···

#!/usr/bin/ruby

require ‘net/ftp’

ftp = Net::FTP.new(‘E0152’)

st = ftp.login(“opecon”, “123”,0)
files = ftp.chdir(’/home/opecon’)

ftp.gettextfile(‘DAILYC’, ‘DAILYC’)
puts "Fetch DailyC Ok"
ftp.gettextfile(‘DAILY’, ‘DAILY’)
puts "Fetch Daily Ok"
ftp.close


#!/usr/local/bin/perl -w

use strict;
use Net::FTP;

my $ics=“E0152”;
my $user = “opecon”;
my $password = “123”;

my $ftp = Net::FTP->new($ics) or die “Can’t connect $@\n”;
$ftp->login($user, $password) or die “Couldn’t login $@\n”;
$ftp->cwd(’/home/opecon’) or die “Couldn’t change directory\n”;
my @lines = $ftp->ls(“DAI*”);

foreach my $line (@lines) {
$ftp->get($line, $line) or die “Can’t fetch $line: $!\n”;
print "Fetch file => ", $line;
print “\n”;
}
$ftp->quit();

Any tips ?

You might try locating the part that is slowest.

#!/usr/bin/ruby

require ‘net/ftp’

ftp = Net::FTP.new(‘E0152’)

puts Time.now
st = ftp.login(“opecon”, “123”,0)
puts Time.now
files = ftp.chdir(’/home/opecon’)
puts Time.now
ftp.gettextfile(‘DAILYC’, ‘DAILYC’)
puts Time.now
ftp.gettextfile(‘DAILY’, ‘DAILY’)
puts Time.now
ftp.close

and take timings at the same point in the perl code and see where the
problem lies.

Does ruby take longer to logon?
Does ruby take longer to CD?
Does ruby take longer to transfer a file?

I also note that perl is just getting the files and ruby is getting a
text file, maybe there is an overhead in ruby hangling a transfer as a
text file (line ending conversion etc) that perl is not having to deal
with. Can’t you just use ftp.getbinaryfile() and see if that speeds
things up. It will at least tell you where the problem might be.