Scripted upload to Liquidfiles server

Discussion in 'LiquidFiles General' started by Jeff Doty, Sep 28, 2017.

  1. Jeff Doty

    Jeff Doty New Member

    Joined:
    Sep 28, 2017
    Messages:
    10
    Likes Received:
    0
    I am trying to setup a script to upload files to part of our liquid files (a file drop folder I think it is called). I am used to scripting in Powershell and I know I can send json commands via powershell, but I am not sure what commands to send. Trying to upload text files (one or several). This is so a vendor can use the data. I looked at the documentation, but there really wasn't any clear examples, at least to me.

    If not json, is it possible to just FTP a file to the liquidfiles server?

    Can anyone help?
     
  2. David

    David Administrator
    Staff Member

    Joined:
    Dec 1, 2015
    Messages:
    796
    Likes Received:
    31
    For inspiration here is a Filedrop API in a Linux shell script https://man.liquidfiles.com/api/sending_files_using_the_filedrop.html so you would need to rewrite that commands to the PowerShell script.
    From my point of view to create a FileDrop API script or any other LF's APIs in Powershell or in Windows batch would be quite exhausting. At first you would need to install Curl for Windows and then in the script create some PowerShell equivalent to the easy Linux shell construction "cat << EOF" for reading input parameters.

    I would rather recommend to install LF's Windows CLI from here: https://man.liquidfiles.com/clients/windows_cli.html
    and then you can easily drop the file in a one row command. It would looks like this:

    LiquidFilesCLI.exe filedrop /k /url:https://lf.domain.com/filedrop/testdrop /f:c:\somefile.txt /from:sender@dom.com /subject:"Test message" /msg:"Some message text"
    (The "testdrop" is a global FileDrop which has been created in "Admin > Configuration > Filedrop > Add Filedrop" settings)

    To see more options please type "LiquidFilesCLI.exe filedrop /help"

    According to the FTP service:
    In the LF appliance you can create a basic FTP service named FTPDir which allows to upload/downloads files or dirs via FTP/FTPS/SFTP protocols.
    This can be set up in "Admin > Configuration > FTPDir".
     
  3. Jeff Doty

    Jeff Doty New Member

    Joined:
    Sep 28, 2017
    Messages:
    10
    Likes Received:
    0
    Thanks, I will give this a try.
     
  4. Toby G.

    Toby G. New Member

    Joined:
    Oct 10, 2017
    Messages:
    3
    Likes Received:
    0
    I think it's entirely possible to upload files via Powershell. I wrote an archival Powershell script to download everyone's message attachments since LiquidFiles has yet to implement archival (that I know of). I haven't had a need to upload files so I've not gone down that path.

    Everything revolves around Invoke-WebRequest.

    Function Get-WebPage {
    param
    (
    [String]$APIKey,
    [String]$Website
    )
    $pass = ''
    $pair = "$($apikey):$($pass)"
    $bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
    $base64 = [System.Convert]::ToBase64String($bytes)
    $basicAuthValue = "Basic $base64"
    $headers = @{'Authorization'=$basicAuthValue}
    $page = Invoke-WebRequest -Uri $Website -Headers $headers -ContentType 'application/json' -Method Get -UseBasicParsing | ConvertFrom-Json
    $page
    }

    $adminapi = 'whatever your api key is'
    $page1 = 'https://whatever.whatever.com/filedrop/_the_filedrop_'

    $data = Get-WebPage -APIKey $adminapi -Website $page1
    $data

    This would perform a GET so you could see the page. I don't think it would be terribly difficult to rework the Invoke-WebRequest to upload a file. If you write a lot of Powershell, it'd be a nice learning experience. Using something like 'RESTLet' in Chrome is helpful for testing out these sorts of web requests. The reason I mention that is I had a lot of trouble with the Windows version of CURL so your mileage may very.
     
  5. Don Wright

    Don Wright New Member

    Joined:
    Feb 17, 2018
    Messages:
    1
    Likes Received:
    0
    Thanks for posting this Toby. Using your script as a start I wrote one to do a bulk import of all of my Exchange users. I plan on creating another to generate a filedrop for each of them and then automatically drop incoming attachments and pull from their mailboxes.
     
  6. Toby G.

    Toby G. New Member

    Joined:
    Oct 10, 2017
    Messages:
    3
    Likes Received:
    0
    Awesome. Glad it helped.
     

Share This Page