Creating an n8n workflow based on your requirements involves a sequence of nodes that perform each task you've outlined. Below is a detailed description of how to create the n8n workflow, including the nodes that you would need and their configurations.
Step-by-Step n8n Workflow Configuration
- FTP Node: Download the
.gz file.
- Execute Command Node: Unzip the
.gz file.
- Execute Command Node: Unzip the
.tar file.
- Execute Command Node: Zip the
.txt file.
- Excel Node: Read data from the
.xlsx file.
- Read Binary File Node: Read the original
.oft file.
- Function Node: Update the
.oft file content based on Excel data.
- Email Node: Send the updated
.oft file.
Example n8n Workflow Configuration
Here’s how to configure each node in your n8n workflow:
1. FTP Node (Download .gz)
- Operation: Download File
- FTP Server: Fill in your FTP server details.
- File Path: Specify the path of the
.gz file on the server.
- Download Path: Specify where to save the downloaded file locally (e.g.,
/tmp/downloaded_file.gz).
2. Execute Command Node (Unzip .gz)
- Command:
gunzip -f /tmp/downloaded_file.gz
- Ensure you have access to the shell commands on your n8n instance.
- Connect to the next node.
3. Execute Command Node (Unzip .tar)
- Command:
tar -xf /tmp/unzipped_file.tar -C /tmp/extracted_directory/
- Ensure there's an extraction directory created or alter the command to create it.
- Connect to the next node.
4. Execute Command Node (Zip .txt file)
- Command:
zip -j /tmp/zipped_file.zip /tmp/extracted_directory/file.txt
- Update the file names as appropriate.
- Connect to the next node.
5. Excel Node (Read .xlsx)
- Operation: Read
- File Path: Specify path for the
.xlsx file you extracted from the tar.
- Sheet Name: Specify the sheet you want to read.
- Output Format: Set to JSON so data can be easily processed later.
6. Read Binary File Node (Read .oft)
- File Path: Provide the path to your existing
.oft file.
- Store binary data for later use.
7. Function Node (Update .oft)
In this node, you will process the .oft file to replace placeholders with values from the Excel file.
Example code in the Function node:
let updatedOFT = Buffer.from(items[1].binary.data, "base64").toString("utf-8"); // Access the .oft content
const newValue = items[0].json["Column2"]; // Example of retrieving data from Excel, replace with actual column names
updatedOFT = updatedOFT.replace(/{{placeholder}}/g, newValue); // Replace with actual placeholder
return [{json: { updatedOFT: updatedOFT }}];
8. Email Node (Send .oft)
- SMTP settings: Configure your SMTP server details.
- To: Enter the recipient's email address.
- Subject: Specify the subject line.
- Body: Write your message body.
- Attachments: Use the binary data from the previous Function node, e.g.:
- Name:
new_email.oft (or your preferred name).
- Data:
{{$json["updatedOFT"]}}.
Complete Workflow JSON
Here’s a basic outline JSON representation of how the workflow nodes would look. Please adjust any specific paths, parameters, and settings based on your environment.
{
"nodes": [
{
"parameters": {
"operation": "download",
"filePath": "/path/to/your/file.gz",
"downloadPath": "/tmp/downloaded_file.gz"
},
"name": "FTP Download",
"type": "n8n-nodes-base.ftp",
"typeVersion": 1
},
{
"parameters": {
"command": "gunzip -f /tmp/downloaded_file.gz"
},
"name": "Unzip GZ",
"type": "n8n-nodes-base.executeCommand",
"typeVersion": 1
},
{
"parameters": {
"command": "tar -xf /tmp/unzipped_file.tar -C /tmp/extracted_directory/"
},
"name": "Unzip TAR",
"type": "n8n-nodes-base.executeCommand",
"typeVersion": 1
},
{
"parameters": {
"command": "zip -j /tmp/zipped_file.zip /tmp/extracted_directory/file.txt"
},
"name": "Zip TXT",
"type": "n8n-nodes-base.executeCommand",
"typeVersion": 1
},
{
"parameters": {
"filePath": "/tmp/extracted_directory/data.xlsx",
"sheetName": "Sheet1"
},
"name": "Read Excel",
"type": "n8n-nodes-base.xlsx",
"typeVersion": 1
},
{
"parameters": {
"filePath": "/path/to/your/template.oft"
},
"name": "Read OFT",
"type": "n8n-nodes-base.readBinaryFile",
"typeVersion": 1
},
{
"parameters": {
"functionCode": `let updatedOFT = Buffer.from(items[1].binary.data, "base64").toString("utf-8");
const newValue = items[0].json["Column2"];
updatedOFT = updatedOFT.replace(/{{placeholder}}/g, newValue);
return [{json: { updatedOFT: updatedOFT }}];`
},
"name": "Update OFT",
"type": "n8n-nodes-base.function",
"typeVersion": 1
},
{
"parameters": {
"fromEmail": "example@example.com",
"toEmail": "recipient@example.com",
"subject": "Updated OFT",
"text": "Please find the updated OFT file attached.",
"attachments": [
{
"name": "updated.oft",
"data": "{{$json[\"updatedOFT\"]}}"
}
]
},
"name": "Send Email",
"type": "n8n-nodes-base.emailSend",
"typeVersion": 1
}
],
"connections": {
"FTP Download": {
"main": [
[
{
"node": "Unzip GZ",
"type": "main",
"index": 0
}
]
]
},
"Unzip GZ": {
"main": [
[
{
"node": "Unzip TAR",
"type": "main",
"index": 0
}
]
]
},
"Unzip TAR": {
"main": [
[
{
"node": "Zip TXT",
"type": "main",
"index": 0
}
]
]
},
"Zip TXT": {
"main": [
[
{
"node": "Read Excel",
"type": "main",
"index": 0
}
]
]
},
"Read Excel": {
"main": [
[
{
"node": "Read OFT",
"type": "main",
"index": 0
}
]
]
},
"Read OFT": {
"main": [
[
{
"node": "Update OFT",
"type": "main",
"index": 0
}
]
]
},
"Update OFT": {
"main": [
[
{
"node": "Send Email",
"type": "main",
"index": 0
}
]
]
}
}
}
Importing Your Workflow
- Open n8n and go to Workflows.
- Click on the Import option.
- Paste the JSON code from above and import the workflow.
Finalizing Your Workflow
- Ensure to update your specific paths and adjust any configurations based on your environment and personal settings.
- Test the workflow step-by-step to ensure that each section operates correctly.
This workflow will give you a robust system to automate the process you’ve specified. Feel free to customize it further to meet any additional needs!