I needed an easy way to push documents to the KT implementation. After looking at how KT’s windows drop box software works I wrote something similar in Perl that works from the command line.
I plan to wrap an Automator action around this to upload documents easily.
#stephen
#www.stephenjc.com
#ktdrop.pl
#command line drop box
#usage: ./ktdrop.pl username password fullpath_to_file
use SOAP::Lite;
use Data::Dumper;
use LWP::UserAgent;
use HTTP::Request::Common;
use XML::Simple;
#username and password for KT
$username = $ARGV[0];
$password = $ARGV[1];
#prefix http or https
$serverPre = 'https://';
#full server url with port
$serverUrl = 'server.com:port/kt';
#document type for uploaded documents, make sure nothing is required because we will not send any metadata
$ktDocumenttype = 'default';
#if you have http basic leave this, otherwise change it to ''
$httpAuth = $username . ':' . $password . '@';
$fullUrl = $serverPre.$httpAuth.$serverUrl.'/ktwebservice/';
$session = SOAP::Lite->new(proxy => $fullUrl . 'webservice.php?wsdl');
$file = $ARGV[2];
#login
$r = $session->login($username,$password,'127.0.0.1');
$ktsessionid = $r->valueof('//message');
#dropbox folder id for user
$r = $session->get_folder_detail_by_name($ktsessionid,"DroppedDocuments/$username");
$dropboxid = $r->valueof('//id');
#upload document
$uploadRes = ktUpload();
#move file to dms
$r = $session->add_document($ktsessionid,$dropboxid,$uploadRes->{name},$uploadRes->{name},$ktDocumenttype,$uploadRes->{filename});
if ($r->valueof('//status_code') == 0)
{
$r = $session->logout($ktsessionid);
exit(0);
}
else
{
print "The upload did not work\n";
exit(1);
}
sub ktUpload
{
my $ua = LWP::UserAgent->new;
my $browser = HTTP::Request->new();
my $response = $ua->request(POST $fullUrl . 'upload.php',
Content_Type => 'form-data',
Content =>[
session_id => $ktsessionid,
action => "A",
output => "xml",
file => [$file]
]
);
my $uploadres = XMLin($response->content);
#print Dumper($uploadres->{upload_status}->{file});
return $uploadres->{upload_status}->{file};
}