Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#814731
Hi,

Is it possible to Integration between Processmaker & File server / FTP server?

The requirement is to find a way, after the case approved, the attachment can be saved automatically (in certain way / Protocol) to another server (normally FTP) for further operation / process.

Please confirm and suggest a better way to approach.

regards,
Raja
#814744
What version of ProcessMaker do you have?

In the final task of your process, you can a trigger like the following to save all the files from the current case to your FTP server:
Code: Select all
$ftpServer = 'my.example.com';
$ftpPath = '/var/www/pmFiles'; //set to the file path on the FTP server
$ftpUser = 'johnDoe';
$ftpPass = 'p4sSw0rD';

$caseId = @@APPLICATION;
$sql = "SELECT * FROM APP_DOCUMENT WHERE APP_UID='$caseId' AND APP_DOC_STATUS='ACTIVE'";
$aFiles = executeQuery($sql);

//first add the directory with case number to the FTP server:
$connection = ssh2_connect($ftpServer, 22);  //set to the domain of the remote server
ssh2_auth_password($connection, $ftpUser, $ftpPass); 
$sftp = ssh2_sftp($connection);

//create directory for the case number on the FTP server:
$ftpCaseDir = $ftpPath .'/'. @@APP_NUMBER;
ssh2_sftp_mkdir($sftp, $ftpCaseDir);

//lookup the files for the current case:
$caseId = @@APPLICATION;
$sql = "SELECT * FROM APP_DOCUMENT WHERE APP_UID='$caseId' AND APP_DOC_STATUS='ACTIVE'";
$aFiles = executeQuery($sql);
$g = new G();

foreach ($aFiles as $aFile) {
    $filename = $aFile['APP_DOC_FILENAME'];

    if ($aFile['APP_DOC_TYPE'] != 'OUTPUT') {
        $ext = pathinfo($filename, PATHINFO_EXTENSION);
        $filePath = PATH_DOCUMENT . $g->getPathFromUID($caseId) .PATH_SEP. 
            $aFile['APP_DOC_UID'] .'_'. $aFile['DOC_VERSION'] .'.'. $ext;

        //check if the file already exists. If so, then add an incrementing number to the filename:
        $aDirList = ftp_nlist($connection, $ftpCaseDir);
        $ftpFilePath = $ftpCaseDir .'/'. $filename;
        $i = 1;

        while ( in_array($ftpFilePath, $aDirList) ) {
           $i++;
           $ftpFilePath =  $ftpCaseDir .'/'. $filename .'_'. $i .'.'. $ext; 
        }

        ssh2_scp_send($connection, $filePath, $ftpFilePath);
    }
    else {  //if Output Document file
        //code for output documents is similar but I don't have time right now
    } 
}
This code will work in PM 3.1 and later. I'll post code for output Docs later this week when I find the time.

Thanks Amos Perfect, you were right, my variable […]

Hi, I've written a trigger with the following con[…]

What version of PM are you using? You should use a[…]

First of all, do you know PHP and JavaScript? If […]