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);
In reply to client server file transfer by Boots111
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |