Hi community,
I got half a script which intended to download a txt file form a sharepoint server. After struggled with SOAP in perl and the amazingly un-user friendly XML, I finally got the below script worked for authentication and retriving.
Code:
use LWP::UserAgent;
use LWP::Debug;
use SOAP::Lite on_action => sub { "$_[0]$_[1]"; };
use MIME::Base64 qw( decode_base64 );
use MIME::Base64 qw(encode_base64);
#use SOAP::Lite;
import SOAP::Data 'name', 'value';
SOAP::WSDL::Deserializer::Hash;
$sp_endpoint = 'https://remote.domain.com:345/_vti_bin/Copy.asmx';
$sp_domain = 'remote.domain.com:345';
$sp_username = '192.168.133.124\meowdin';
$sp_password = 'meowdin';
$debug = 1;
if ($debug) {
LWP::Debug::level('+');
SOAP::Lite->import(+trace => 'all');
}
my @ua_args = (keep_alive => 1);
my @credentials = ($sp_domain, "", $sp_username, $sp_password);
my $schema_ua = LWP::UserAgent->new(@ua_args);
$schema_ua->credentials(@credentials);
$soap = SOAP::Lite->proxy($sp_endpoint, @ua_args, credentials => @credentials);
$soap->schema->useragent($schema_ua);
$soap->uri("http://schemas.microsoft.com/sharepoint/soap/");
$soap->transport->credentials( @credentials );
$url="https://remote.domain.com:345/Shared%20Documents/test.txt";
$list=$soap->GetItem(SOAP::Data->value(SOAP::Data->name("Url" => $url)));
quit(1, $list->faultstring()) if defined $list->fault();
my $result=$list->dataof('//GetItemResponse/Stream');
my $file = "time.txt";
$content=decode_base64($result);
#Supposed I am having my file in memory as $content
#But I find noway for me to put this memory into physical
Here's the SOAP format specification in that sharepoint server for reference
Code:
Request:
POST /_vti_bin/Copy.asmx HTTP/1.1
Host: remote.bizconline.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/GetItem"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetItem xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<Url>string</Url>
</GetItem>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
Response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetItemResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<GetItemResult>unsignedInt</GetItemResult>
<Fields>
<FieldInformation Type="Invalid or Integer or Text or Note or DateTime or Counter or Choice or Lookup or Boolean or Number or Currency or URL or Computed or Threading or Guid or MultiChoice or GridChoice or Calculated or File or Attachments or User or Recurrence or CrossProjectLink or ModStat or AllDayEvent or Error" DisplayName="string" InternalName="string" Id="guid" Value="string" />
<FieldInformation Type="Invalid or Integer or Text or Note or DateTime or Counter or Choice or Lookup or Boolean or Number or Currency or URL or Computed or Threading or Guid or MultiChoice or GridChoice or Calculated or File or Attachments or User or Recurrence or CrossProjectLink or ModStat or AllDayEvent or Error" DisplayName="string" InternalName="string" Id="guid" Value="string" />
</Fields>
<Stream>base64Binary</Stream>
</GetItemResponse>
</soap:Body>
</soap:Envelope>
It could be possible that I made a wrong assumption and the $content is not containing the file I retrived (the XML return with a chunk of glibberish tho).
Or it could possibly be a simple solution (like the puttofile($content) method in my dream)
In anycase, I will appreciate any input, or even any other approach / method.
I got to run this script on a Linux machine (CentOS or something) tho, so M$ solution could not really help here
Mao Ting
---------- Post added at 06:02 PM CDT ---------- Previous post was at 04:09 PM CDT ----------
Some update:
I have modified my code (the lower part) with these:
Quote:
my @result=$list->dataof('//GetItemResponse/Stream');
my $file = "time.txt";
my $attr="";
open ( FH2 ,">", $file ) || die ("Could not open file. $!");
foreach $data(@result){
$attr= $data->attr;
$content=decode_base64($attr);
print FH2 (utf8::encode($content));
}
|
It seems the attribute is what I want, and I need to use an array inorder to get them all.
Enven though I get glibberish still, I think I am getting closer ...
Again, any help is much appreciated.