The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. December 05, 2008, 10:09:26 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: multithreaded ftp upload  (Read 1155 times)
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 1141


View Profile
« on: July 01, 2007, 09:22:39 PM »

small example how to upload with ftp with threads using perl.

domains.lst -> file containing sites ie spammy.somesite.com
username in this case would be spammy.
where script is are contained folders named like "spammy.somesite.com" that matches list in domains.lst

Code:
#!/usr/bin/perl -w
use strict;
use warnings;
use threads;
use Thread::Queue;
use Net::FTP;

sub readlines {
    my($filename, @lines); 
    ($filename) = @_;
    open FREEHOSTS, "<$filename";
    while (my $line = <FREEHOSTS>) {
       chomp($line);
       push @lines,$line;
       }
    close FREEHOSTS;
    return @lines;
}

my $ftp_password : shared;
$ftp_password = "secret";

my $DomainQueue = Thread::Queue->new;
$DomainQueue->enqueue(readlines("domains.lst"));
print $DomainQueue->pending . "\n";
my @thrs;

for(my $thr_id=0;$thr_id<6;$thr_id++) {
    my $thr = threads->new(sub {
        while (my $domain = $DomainQueue->dequeue_nb) {
            print "starting $domain\n";
            my @parts = split("\\.",$domain);
            my $ftp_user = shift @parts;
            next unless my $ftp = Net::FTP->new($domain, Debug => 0);
            next unless $ftp->login($ftp_user,$ftp_password);
            foreach my $filename (glob($domain . "/*.html")) {
                $ftp->put($filename);
                }
            $ftp->quit();
            print "done $domain\n";
            }});
    push(@thrs,$thr);
}

foreach my $thr (@thrs) {
    $thr->join;
}
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!