How can I upload a document to SharePoint with Perl?

夙愿已清 提交于 2019-12-04 08:17:02

This sounds like a job for WWW::Mechanize. It has excellent support for dealing with forms.

Just found an easy way on windows from perlmonks forum:

http://www.perlmonks.org/?node_id=527182
under Windows, you can access a sharepoint site via a UNC name. The URL:
sharepoint.domain.dom/sites/Roboticus/Test
is accessible via:
\\sharepoint.domain.com\sites\Roboticus\Test

just adding as answer to myself, now I got to figure out how to script this from Perl and whether there is way to do the same from script running on unix.

Can you use the Webdav interface? Each SharePoint list has a webdav folder associated with it.

Ken Venner

To make NTLM authentication work in WWW::Mechanize you need to use this format

use URI;
my $u    = URI->new($url);
my $host = $u->host;
my $port = $u->port;
my $hostport = "$host:$port";

$agent->$self->credentials($hostport, $realm, $user, $password);
vvrao

You can connect to SharePoint (or any website) using curl, which is able to authenticate and perform negotiation with Kerberos/NTLM:

curl --ntlm -u domain/userid:passwd -T <file> "http://sharepoint URL" 
  • --ntlm
    (HTTP) Enables NTLM authentication. The NTLM authentication method was designed by Microsoft and is used by IIS web servers. It is a proprietary protocol, reverse-engineered by clever people and implemented in curl based on their efforts. This kind of behavior should not be endorsed, you should encourage everyone who uses NTLM to switch to a public and documented authentication method instead, such as Digest.

    If you want to enable NTLM for your proxy authentication, then use --proxy-ntlm.

    This option requires a library built with SSL support. Use -V, --version to see if your curl supports NTLM.

    If this option is used several times, only the first one is used.

  • -u, --user

    Specify the user name and password to use for server authentication. Overrides -n, --netrc and --netrc-optional.

    If you simply specify the user name, curl will prompt for a password.

    The user name and passwords are split up on the first colon, which makes it impossible to use a colon in the user name with this option. The password can, still.

    When using Kerberos V5 with a Windows based server you should include the Windows domain name in the user name, in order for the server to successfully obtain a Kerberos Ticket. If you don't then the initial authentication handshake may fail.

    When using NTLM, the user name can be specified simply as the user name, without the domain, if there is a single domain and forest in your setup for example.

    To specify the domain name use either Down-Level Logon Name or UPN (User Principal Name) formats. For example, EXAMPLE\user and user@example.com respectively.

    If you use a Windows SSPI-enabled curl binary and perform Kerberos V5, Negotiate, NTLM or Digest authentication then you can tell curl to select the user name and password from your environment by specifying a single colon with this option: "-u :".

    If this option is used several times, the last one will be used.

  • -T, --upload-file

    This transfers the specified local file to the remote URL. If there is no file part in the specified URL, Curl will append the local file name. NOTE that you must use a trailing / on the last directory to really prove to Curl that there is no file name or curl will think that your last directory name is the remote file name to use. That will most likely cause the upload operation to fail. If this is used on an HTTP(S) server, the PUT command will be used.

    Use the file name "-" (a single dash) to use stdin instead of a given file. Alternately, the file name "." (a single period) may be specified instead of "-" to use stdin in non-blocking mode to allow reading server output while stdin is being uploaded.

    You can specify one -T for each URL on the command line. Each -T + URL pair specifies what to upload and to where. curl also supports "globbing" of the -T argument, meaning that you can upload multiple files to a single URL by using the same URL globbing style supported in the URL, like this:

    curl -T "{file1,file2}" http://www.uploadtothissite.com

    or even

    curl -T "img[1-1000].png" ftp://ftp.picturemania.com/upload/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!