Forum Discussion
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 m...
Apr 28, 2011
Here's how I did it in the PerlConfigSync CodeShare entry (also as included in the SDK).
http://devcentral.f5.com/wiki/default.aspx/iControl/PerlConfigSync.html
I just tested it and it worked with both binary (.exe) and text files.
sub uploadFile()
{
my ($localFile, $configName, $quiet) = (@_);
$success = 0;
if ( "" eq $configName )
{
$configName = $localFile;
}
if ( "" eq $localFile )
{
&usage("upload");
}
$bContinue = 1;
$chain_type = $FILE_FIRST;
$preferred_chunk_size = $defaultChunkSize;
$chunk_size = $defaultChunkSize;
$total_bytes = 0;
open(LOCAL_FILE, "<$localFile") or die("Can't open $localFile for input: $!");
binmode(LOCAL_FILE);
while (1 == $bContinue )
{
$file_data = "";
$bytes_read = read(LOCAL_FILE, $file_data, $chunk_size);
if ( $preferred_chunk_size != $bytes_read )
{
if ( $total_bytes == 0 )
{
$chain_type = $FILE_FIRST_AND_LAST;
}
else
{
$chain_type = $FILE_LAST;
}
$bContinue = 0;
}
$total_bytes += $bytes_read;
$FileTransferContext =
{
file_data => SOAP::Data->type(base64 => $file_data),
chain_type => $chain_type
};
$soap_response = $ConfigSync->upload_file
(
SOAP::Data->name(file_name => $configName),
SOAP::Data->name(file_context => $FileTransferContext)
);
if ( $soap_response->fault )
{
if ( 1 != $quiet )
{
print $soap_response->faultcode, " ", $soap_response->faultstring, "\n";
}
$success = 0;
$bContinue = 0;
}
else
{
if ( 1 != $quiet )
{
print "Uploaded $total_bytes bytes\n";
}
$success = 1;
}
$chain_type = $FILE_MIDDLE;
}
print "\n";
close(LOCAL_FILE);
return $success;
}
-JoeRecent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects