Straatos FTP Service

Target

The FtpService and ZipService provide a service to allow ftp to get, put, move and delete functionality to script activities.

The Script service API describes the available calls for the developer writing javascript activities.

FtpGet Service

Get a file from an ftp server (to download as a binary stream)

 

Parameters:

 

FtpUrl

Url to connect to the ftp server, prefixed with the protocol to use (ftp, ftps, sftp are currently supported). When postfixed with a path, all file paths will be relative to this directory. The FtpUrl can be followed by an additional path. This will be the base directory. The FilePath parameter has to be specified relative to this path. See the example below.

FtpUser

Ftp user used to connect

FtpPassword

Ftp password

FilePath

The path of the file to get, relative to the base directory defined in the FtpUrl

 

The sample script below gets a document from the ftp server and adds the document as AdditionalData to the workflow task.

    // FTP Get
    var ftpSettings = {
          FtpUrl: 'sftp://...',
          FtpUser: '<your username>',
          FtpPassword: '<your password>',
          FilePath: 'Files/File.xml'
    };
    
    var formData = straatos.newFormData();
    formData.append(straatos.adapter.ftpGet(ftpSettings));
    straatos.adapter.addAdditionalData(_documentId, formData.getByteArray(), '.xml', 'getFTPFile');

 

FtpMove Service

Moves a file from one location to another on the same ftp server

 

FtpUrl

Url to connect to the ftp server, prefixed with the protocol to use (ftp, ftps, sftp are currently supported). When postfixed with a path, all file paths will be relative to this directory

FtpUser

Ftp user used to connect

FtpPassword

Ftp password

FilePathFrom

The path of the file to move, relative to the base directory defined in FtpUrl

FilePathTo

The complete filename of the destination file, relative to the base directory defined in the FtpUrl

 

The script below moves a file from one location of the ftp to the other location and renames the file from 'File.xml' to 'moved-file.xml'.

    // FTP Move
    var ftpSettings = {
          FtpUrl:'sftp:/...'
          FtpUser: '<your username>',
          FtpPassword:'<yourpassword>',
          FilePathFrom:'File.xml',
          FilePathTo :'MoveTo/moved-file.xml',  
    };
    
    straatos.adapter.ftpMove(ftpSettings);

 

FtpDelete Service

Deletes a file from the ftp server

 

FtpUrl

Url to connect to the ftp server, prefixed with the protocol to use (ftp, ftps, sftp are currently supported). When postfixed with a path, all file paths will be relative to this directory

FtpUser

Ftp user used to connect

FtpPassword

Ftp password

FilePath

The path of the file to delete, relative to the base directory defined in FtpUrl

 
The following sample script deletes a file from the ftp server.
    // FTP Delete
    var ftpSettings = {
          FtpUrl: 'sftp://...',
          FtpUser: '<your user>',
          FtpPassword: 'your password>',
          FilePath: 'MoveTo/moved-file.xml'
    };
    
    straatos.adapter.ftpDelete(ftpSettings);

 

FtpPut Service

Uploads a file from the AdditionalData of a document or original document to the ftp server. The file can be stored on the document by, for example, the Zip service

 

FtpUrl

Url to connect to the ftp server, prefixed with the protocol to use (ftp, ftps, sftp are currently supported). When postfixed with a path, all file paths will be relative to this directory

FtpUser

Ftp user used to connect

FtpPassword

Ftp password

FilePath

The path of the file to save, relative to the base directory defined in FtpUrl. Depending on ftp server behaviour, the file is overwritten when it already exists, or an error will be thrown.

DocumentId

DocumentId of document to get file from, required

AdditionalDataKey

The key where the additional data is stored under (so not the URL), required

CreateDirectories (Optional) When set to true the FtpPut service makes sure the directory structure of FilePath is created before the file is uploaded (the ftp user must have the rights to create directories).

 

 

 
The following script takes a file stored in the AdditionalData with key 'test-xml' and uploads it onto the ftp server as 'File.xml'.
    // FTP Put - AdditionalData
    var ftpSettings = {
           FtpUrl: 'sftp://...',
           FtpUser: '<your username>',
           FtpPassword: '<your password>',
           FilePath: 'File.xml'
           AdditionalDataKey:'test-xml',
    };
    
    straatos.adapter.ftpPut(ftpSettings);

 

The following script takes the original document and uploads it onto the ftp server.

    // FTP Put - Original document
    var ftpSettings = {
           FtpUrl: 'sftp://...',
           FtpUser: '<your username>',
           FtpPassword: '<your password>',
           FilePath: 'File.pdf'
           AdditionalDataKey:'test-xml',
           UseOriginalDocument: true,
           UploadFileUrl: documentInfo.originalURL + '?w=' + straatos.webserviceKey,
           CreateDirectories : true
    };
    
    straatos.adapter.ftpPut(ftpSettings);

 

FtpPutFile Service - discontinued

Uploads a file to the Ftp server

 

Use the FtpPut service instead

 

FtpUrl

Url to connect to the ftp server, prefixed with the protocol to use (ftp, ftps, sftp are currently supported). When postfixed with a path, all file paths will be relative to this directory

FtpUser

Ftp user used to connect

FtpPassword

Ftp password

FtpFile

The path(optional)+filename of the file to be stored, relative to the base directory defined in FtpUrl. When only the fileName is provided, it will be stored in the base directory.

 

 

The body should contain the file to upload to the Ftp server, as a binary stream (byte array), so not encoded. For example, a straatos.ajax() call with a dataType ‘binary’ returns a binary stream that can be passed as the body of this call. Also, the FtpGet method described earlier returns a similar stream, allowing for getting a file from one ftp server and upload it to another ftp server.

 

The following script gets the document URL from the additional data for a file 'test-xml'. The script then retrieves the binary of the file via the straatos.ajax call. If the call is successful, the file is uploaded to the FTP Server.

    var ftpSettings = {
          FtpUrl: 'sftp://...', 
          FtpUser: '<your username>', 
          FtpPassword: '<your password>', 
          FilePath: 'File.xml'
    };

    var documentInfo = straatos.adapter.getDocumentInfo();
    var filetosendURL = documentInfo.additionalData.filter(function (additionalData) { return additionalData.key == 'test-xml'; })[0].url;
    
    straatos.adapter.setDocumentRestrictions({URL: filetosendURL,AccessCount: 1});
    
    straatos.ajax({
           url : filetosendURL,
           dataType : 'binary'
    }).done(function(fileToSend) {
        straatos.adapter.ftpPutFile(fileToSend,ftpSettings,60000);
    }).fail(function(jqXHR, error){
        console.log('FTPPutFile Error: ' + error);
    });

 

Zip Service

Zips a list of files and returns the zipfile as a binary stream. The files to zip can either be specified as a string (they will be interpreted as UTF8 encoded) or a http url can be specified, the service downloads the files and zips them.

 

Protocol: HTTPS

Method: POST

Url: https://effektif-adapter-xxx.cumuluspro.net/AdapterService.svc/json/Zip

Headers:

“Content-Type” : “application/json"

 

Webservice parameters:

 

WebServiceKey

WebServiceKey found under Organization in AdminPanel

DocumentId

DocumentId of document to attach the file to.

AdditionalDataKey

The key where the additional data is stored under (so not the URL)

Files

A files array. Each object in the array should be a json object containing 2 (out of the possible 3) keys: FileName, SourceUrl and UTF8Content.

FileName: Mandatory, a string containing the filename to use in the zip.

SourceUrl: When this is a valid URL, the file is downloaded from this url and added to the zip.

UTF8Content: When SourceUrl is empty and UTF8Content has a value, the value of this parameter is stored in a text file and added to the zip.

 

 

Return Value:

Upon success Http status 200 is returned with a string as body. This string contains the full url of how the zip document can be obtained (via a GET). On error Http status 400 is returned, with a string describing the error in the body.

 

Example Json:

{
	"WebServiceKey" : "6as888rt-ww4r-4061-g821-qq644f736466",
	"DocumentId": _documentId,
	"AdditionalDataKey": "the-zip-file",
	"Files" : [
		{ "FileName" : "1.jpg", 
		  "SourceUrl" : "https://someurl.cloudfront.net/file0.jpg", 
		  "UTF8Content" : ""
		},
		{ "FileName" : "2.jpg", 
		  "SourceUrl" : "https://someurl.cloudfront.net/file1.jpg", 
		  "UTF8Content" : ""
		},
		{ "FileName" : "tt.txt", 
		  "SourceUrl" : "", 
		  "UTF8Content" : "And this text is put in a separate file (tt.txt)"
		}
	]
}

 

Example Straatos call:

This example downloads the two images defined in the Files[] array in a zip and stores the result as additional data. Also, a text file is added to the zip, containing the text “And this text is put in a separate file (tt.txt)”

 

// Get Document Info
var zipInput = {
    "AdditionalDataKey": "the-zip-file",
    "Files" : [
        { "FileName" : "1.jpg", 
         "SourceUrl" : "https://someurl.cloudfront.net/file0.jpg", 
        },
        { "FileName" : "2.jpg", 
         "SourceUrl" : "https://someurl.cloudfront.net/file1.jpg", 
        },
        { "FileName" : "tt.txt", 
         "UTF8Content" : "And this text is put in a separate file (tt.txt)"
        }
    ]
};
try {
    var zipFile = straatos.adapter.zip(zipInput);
    response.body = 'Ok! The file can be downloaded via this url: ' + zipFile;
} catch(err) {
    response.body = 'Error: ' + err;
    straatos.SetError('Error: ' + err);
    console.log('Error: ' + err);
}
Create your own Knowledge Base