Boots111 has asked for the wisdom of the Perl Monks concerning the following question:
and for the client:sub SendFile { my($to, $file) = @_; print $to "Sending $file:\n"; open(IN, $file) || die("Could not open $file: $!\n"); binmode(IN); print $to <IN>; print $to "\nEND\n"; close IN; }
Originally I tried to do this without the little END tag; however that produced odd results. The client would seem to hang until the server was killed, at which point the client would recieve the file. Because I didn't know whether this one was should happen or not, I wrote the following test program:sub RecieveFile { my($server) = $_[0]; $line = <$server>; $line =~ /Sending (.*):/; print("Receiving $1...\n"); open(OUT, ">$1.cpy") || die("Cannot open $1.cpy: $!\n"); binmode(OUT); while(($_ = <$server>) ne "END\n") { print OUT; } close(OUT); print("Finished\n"); }
This program copies the file specified in its first agrument. Moreover this program works perfectly. Then I guessed that maybe (due to the client-server system) there was no way to specify that I had finished sending the binary output, so I added a newline character where the END tag currently is. That had the unfortunate result of sending will more then triple the actual file size to the program. Thus I came up with the END tag you see here.use strict; open(IN, $ARGV[0]); binmode(IN); open(OUT, ">$ARGV[0].cpy"); binmode(OUT); print OUT <IN>; close(OUT); close(IN);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: client server file transfer
by repson (Chaplain) on Jun 23, 2001 at 14:24 UTC | |
by Boots111 (Hermit) on Jun 25, 2001 at 16:58 UTC | |
Re: client server file transfer
by dimmesdale (Friar) on Jun 23, 2001 at 01:04 UTC | |
by Boots111 (Hermit) on Jun 23, 2001 at 01:12 UTC | |
by clintp (Curate) on Jun 23, 2001 at 07:02 UTC |