Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Client for custom file server

by Aighearach
on Apr 27, 2000 at 00:02 UTC ( #9314=sourcecode: print w/replies, xml ) Need Help??
Category: Network
Author/Contact Info Paris Sinclair programmer@makeyourbanner.com
Description: This is the client program for my custom file server, written for inclusion in bots on the Free Internet Chess Server.
#!/usr/bin/perl -w
use IO::Socket;
use strict;

unless (@ARGV >= 3) { die "usage: $0 server port file(s)\n"; }
my ($server, $port, @file_list) = @ARGV;
my ($buffersize, $buffer, $data, $file, $connection) = (1024);

if ($file_list[0] eq '*') {
    @file_list = get_file_list('.');
}
foreach $file (@file_list) {
    my $size = (stat($file))[7];
    my  $retry_count = 0;
    open(FILE, $file);
    binmode FILE; 
    until ($connection = IO::Socket::INET->new(Proto => "tcp",
                           PeerAddr => $server,
                           PeerPort => $port) || (++$retry_count) > 30
+) { 
    }
    $connection->autoflush(1);
    print STDERR "[Connected to $server:$port]\n";
    print $connection "[FILENAME: \"_$file\"]\012";
    print $connection "[SIZE: \"$size\"]\012";
    while (read(FILE, $data, $buffersize)) {
    print $connection $data;
    }
    close(FILE);
    sleep(1);
}

sub get_file_list {
    my ($dir) = @_;
    my ($file, @file_list);
    opendir(DIR,$dir) || die "cannot open directory: $!";
    readdir(DIR);
    readdir(DIR);
    while (defined( $file = readdir(DIR) )) {
    push(@file_list, $file);
    }
    return @file_list;
}
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://9314]
help
Chatterbox?
[thezip]: oops... My mind is backwards (this works): find . -mindepth 2 -name "*.csv" | xargs wc -l

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2016-12-06 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (113 votes). Check out past polls.