- Create a New SFTP Configuration Object:
- Go to the Domain Model of your Mendix project.
- Create a new Entity called something like SFTPConnection (or similar).
- Add attributes to this entity, such as:
- Server (type: String) – the SFTP server's address.
- Port (type: Integer) – default port is 22 for SFTP.
- Username (type: String) – the username for authentication.
- Password (type: String) – the password for authentication (ensure security).
- Private Key (type: String) – if you use key-based authentication, you can store the private key here.
- RemotePath (type: String) – path on the remote server.
- Configure SFTP Settings:
- Within your Mendix application, you will configure the SFTPConfiguration object by providing details like the server, username, password/key, and remote directory.
- Setup the SFTP Session:
- In the Java Actions or Microflows, you can create logic to connect to the SFTP server using the configuration stored in the SFTPConnection entity.
- You can use the SFTP Connector module's built-in Java actions for operations such as:
- Upload File to SFTP
- Download File from SFTP
- List Files in a directory on the SFTP server
3. Add Logic to Your Microflows:
- Create a Microflow for Uploading Files:
- Create a Microflow to upload files to the SFTP server.
- Use the relevant Java Action from the SFTP module, such as UploadFileToSFTP or DownloadFileFromSFTP.
- You will need to pass the SFTPConfiguration object and the file to upload/download to these actions.
- Add Error Handling:
- Ensure your Microflow includes error handling (e.g., try-catch for exceptions like connection issues).
- Testing:
- Test the connection and file transfer to ensure it's working as expected.
After you are done with above steps :
- Retrieve the SFTPConnection (from database or system configuration).
- Create a FileDocument (the file you want to upload).
- Call Java Action (e.g., UploadFileToSFTP) with parameters like SFTPConnection and FileDocument.