John_Gruber_432
Apr 28, 2011Historic F5 Account
perl SOAP::Lite and file encoding
I'm having problems using System::ConfigSync::upload_file with SOAP Lite in perl.
In perl everything is working fine when I read in binary files with binmode set. When I read in text files, no matter what type encoding type I put in binmod (utf8 or byte) or if I try and read them in as text without binmode, the XML serialized data for the content has "\n" for every line and the file on the BIG-IP comes shows up as a binary file..all jacked up.
I know the API says char[], but how it is being serialized in SOAP::Lite and then written to the disk on the BIG-IP is not working for me. I jumped over to java and read in the files as byte arrays and, after trimming them up BTW..thanks for that,got everything working with binary and text files. So I'm sure this is a encoding/serialization issue in perl SOAP::Lite.
Anyone have this working in perl with some syntax?
Here is what does not work for text files... It's got a bunch of my module sub in it, but you will get the point.
sub copyFile
{
my ($self,$srcfile,$destfile) = @_;
writelog($self,"debug","Copy source file $srcfile to $destfile");
if( -e $srcfile ) {
my $request = getSoapRequestObject($self, "urn:iControl:System/ConfigSync");
my $buffer;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($srcfile);
open INF, $srcfile or writelog($self,"err","Source file $srcfile can not be opened. $!"); This does work for text files. Tried :byte, :utf8. Tried checking file with if (-B ) and not encoding..doesn't matter
binmode INF, ":bytes";my $blocksize = 65535;
if($size < $blocksize) {
$blocksize = $size;
}
my $bytes_read = 0;
while ( read (INF, $buffer, $blocksize))
{
my $chain_type = "FILE_MIDDLE";
if($bytes_read < 1) {
$chain_type = "FILE_FIRST";
}
elsif (($bytes_read + length($buffer)) eq $size) {
$chain_type = "FILE_LAST";
}
writelog($self,"debug","Writing $destfile ($bytes_read/".length($buffer)."/$size) $chain_type");
my $FileTransferContext = {file_data => $buffer,
chain_type => $chain_type
};
my $response = $request->upload_file(
SOAP::Data->name(file_name => $destfile),
SOAP::Data->name(file_context => $FileTransferContext)
);
if(checkResponse($self,$response)){
$bytes_read = $bytes_read+length($buffer);
} else {
close INF;
return 0;
}
}
close INF;
return 1;
} else {
writelog($self,"err","Source file for copy, $srcfile, does not exist");
return 0;
}
}