problem using socket in perl for linux enviornment
i have problem regarding data tranfer using linux .
i want to transfer file from one linux machine to another
my code for client that send data to server is
#!/usr/bin/perl
use IO::Socket;
$sock = new IO::Socket::INET (PeerAddr => '172.16.40.11',
PeerPort => 50010,
Proto => 'tcp'
);
die "Socket could not be created. Reason: $!\n" unless $sock;
print "enter the filename:";
my $name = <STDIN>;
open(IN,"$name") || die "can't open i/p file";
while(<IN>){
print $sock $_;
print $_;
}
close (IN);
close ($sock);
and the code for the server is:
#!/usr/bin/perl
use IO::Socket;
$sock = new IO::Socket::INET (LocalHost => '172.16.40.11',
LocalPort => 50010,
Proto => 'tcp',
Listen => 10,
);
die "Socket could not be created. Reason: $!" unless $sock;
my $file ="/home/temp/archivefile";
open(SAVAN,">".$file);
chmod(0777,"$file");
while ($new_sock = $sock->accept()) {
while (defined ($buf = <$new_sock>)) {
print SAVAN $buf || die("$!");
print $buf || die();
}
}
close ($sock);
close(SAVAN);
my problem is that i have been successful in data transfer but i can not writ e data in file that is specified by variable $file .
but i m able to write contents of the file that i transfer from machine 172.16.40.1 to machine 172.16.40.11 on STDOUT of machine 172.16.40.11.
how can i write transfered data into file on server 172.16.40.11?
|