use strict; use warnings; use Net::FTP; my $kids; my @kids = (); my @fileList = glob("*.pdf"); open(OUT, ">ftp_test.out") or die; for $kids (1..30){ my @tempList = @fileList; my $start_time = time; while(my @files = splice(@tempList, 0, ($#fileList + 1) / $kids)){ my $pid = fork; push(@kids, $pid); if($pid == 0){ #kid &FTP_SUB(@files); exit; } } waitpid($_, 0) foreach (@kids); my $elapsed_time = time - $start_time; print OUT "Elapsed time with $kids kids:\t$elapsed_time seconds\n"; print "Elapsed time with $kids kids:\t$elapsed_time seconds\n"; } sub FTP_SUB { my @files = @_; my $start_time = time; my $end_time = undef; my $host = '...'; my $user = 'user'; my $pwd = 'pwd'; my $ftp = Net::FTP->new($host, Debug => 0); unless($ftp->login($user,$pass)){ warn "$$:\tCannot login " . $ftp->message; } unless($ftp->cwd("ftp_test")){ warn "$$:\tCannot change directory " . $ftp->message; } foreach my $file (@files){ unless($ftp->put($file)){ warn "$$:\tPut failed " . $ftp->message; } } $ftp->quit; $ftp = undef; }