cnytus has asked for the wisdom of the Perl Monks concerning the following question:

hi,
I am quite new to http::dav and trying to write a script to copy a file to a sharepoint site from Linux. I found couple of sample codeset which does it but when i try it on my environment, i am getting "The keep_alive option must be enabled for NTLM authentication to work. NTLM authentication aborted" error. (below is the debug output from LWP).
Has anyone come across with how to enable the keep_alive for DAV?
Thanks, Cuneyt
LWP::UserAgent::new: () LWP::UserAgent::new: () LWP::UserAgent::request: () LWP::UserAgent::send_request: PROPFIND https://fddld.com/sites/A055/files/ LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 791 bytes LWP::Protocol::collect: read 865 bytes LWP::UserAgent::request: Simple response: Unauthorized LWP::Authen::Ntlm::authenticate: authenticate() has been called LWP::Authen::Ntlm::authenticate: Keep alive not enabled, emitting a warning The keep_alive option must be enabled for NTLM authentication to work. NTLM authentication aborted.

sorry, i forgot to add the code.
#!/usr/bin/perl -w use strict; use warnings; use Getopt::Long; use HTTP::DAV; my $debug = '1'; if ($debug) { LWP::Debug::level('+'); SOAP::Lite->import(+trace => 'all'); } my @ua_args = (keep_alive => 1); #my ( $source, $destination, $username, $password ); my $source = "/home/jadli_r/sharepoint_test/test.txt"; my $destination = "https://fddld.com/sites/A055/files/"; my $username = "uname"; my $password = "passwd"; my $dav = new HTTP::DAV; $dav->credentials( -user =>$username, -pass =>$password, -url =>$destination, ); my $ua = LWP::UserAgent->new( keep_alive => 1 ); $dav->open( -url=>$destination ) or die("Couldnt open $destination: " .$dav->message . "\n"); #if ( $dav->put( -local => "$source", -url => $destination ) ) { # print "\nSuccessfully uploaded $source to $destination\n"; #} #else { # print "Put failed: " . $dav->message . "\n"; #} $dav->put( -local => "$source", -url => $destination )

Replies are listed 'Best First'.
Re: http::dav keep_alive not enabled
by Khen1950fx (Canon) on Jan 06, 2011 at 05:37 UTC
    To enable keep_alive on LWP:

    my $ua = LWP::UserAgent->new( keep_alive => 1 );
      Hi Khen, Thanks for your reply but unfortunately lwp::useragent is getting created as part of dav (i copied the code above) and can't overwrite it by LWP::UserAgent->new( keep_alive => 1 ); . Thanks, Cuneyt

        You can pass in a premade custom user agent (preferrably a HTTP::DAV::UserAgent, constructed with the appropriate parameters, via the -useragent => ... constructor parameter, or at least that's what the source code suggests to me.

        Update: ... and looking at the HTTP::DAV documentation, it even shows how to pass in custom headers.

Re: http::dav keep_alive not enabled
by Khen1950fx (Canon) on Jan 06, 2011 at 13:44 UTC
    Thanks for adding your code. Now we can get down to business. I looked at your code, and it seemed to me that you had too much going on. I didn't see any reason for Getopt::Long; LWP::Debug has been deprecated, and I took out SOAP::Lite. This is how I would approach it:
    #!/usr/bin/perl use strict; use warnings; use HTTP::DAV; my $source = "/home/jadli_r/sharepoint_test/test.txt"; my $destination = "https://fddld.com/sites/A055/files/"; my $username = "uname"; my $password = "passwd"; my $ua = HTTP::DAV::UserAgent->new( keep_alive => 1 ); my $dav = new HTTP::DAV( -useragent => $ua ); $dav->credentials( -user => $username, -pass => $password, -url => $destination, -realm => "DAV realm", ); $dav->open( -url => $destination ) or die("Couldn't open $destination: " .$dav->message . "\n"); $dav->lock( -url => $destination, -timeout => "infinity" ) or die "Put requires infinity\n"; if ( $dav->put( -local => $source, -url => $destination ) ) { print "Successfully uploaded $source to $destination\n"; } else { print "Put failed: " . $dav->message . "\n"; }
    Note that I'm not sure that you'll need keep_alive with an infinite lock.
      Hi,
      you are right, the code was a mess since i was trying everything at once :).
      initialising the dav with useragent fixed the problem.
      my @ua_args = (keep_alive => 1); my $ua = HTTP::DAV::UserAgent -> new (@ua_args); my $dav = HTTP::DAV->new(-useragent => $ua) ;
      thanks a lot for the replies. Cheers, C