Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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;
}

Comment on Client for custom file server
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://9314]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-08-31 01:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls