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.
#815574
You need to have the ftp and openssl extensions installed in PHP. How did you install PM? You can check from the command line on your PM server with the following command:
php -m
(In Windows you will have to first change to the directory where PHP is installed.)
In the list you should see "openssl" and "ftp". If you don't, then you need to install it. In Linux, it is just a matter of installing the package.
In Windows, you will probably need to edit your php.ini file to include it. See:
http://php.net/manual/en/install.pecl.windows.php
If its files are not included in your PHP installation, then you will need to manually download its files and add them to your PHP installation, then include them in the php.ini file.

Thanks buddy.

Hi, Please tell to processmaker team for solu[…]

Hey jamesjohnston, Your first course of action is[…]

https://wiki.processmaker.com/3.2/Case_Summary#Mor[…]