SFTP bug downloading empty files with extension

Hello.

When i try to download with FTP node an empty file with a peculiar extension it throws an error:

ERROR: Expected the input argument to be of type Uint8Array or Buffer or ArrayBuffer, got object

Steps to reproduce:

Create an empty txt file.

empty.txt

Try to download it with FTP node. It downloads fine.

Rename that file to empty.dat

Try to download again. It throws the error

ERROR: Expected the input argument to be of type Uint8Array or Buffer or ArrayBuffer, got object

Why is that? We need to download these files although they are empty.

In hex view you can see they are identical

.txt

.dat

But the .dat throws the error i mentioned above.

Hey @Mulen,

Just done a quick test here and I have reproduced the same issue, Even though you put SFTP in the title I did a test with FTP as well and that is working so I assume it is something different about the library being used for SFTP or how the returned data is handled.

Yes sorry i tried only with sftp.

So it’s a minor bug then that exists. Hope the devs pick it up.

Thanks.

Thanks for reporting this Mulen!

Seeing this is an empty file, would you be able to simply create it yourself instead of downloading for the time beeing?

For example like so:

{
  "nodes": [
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "nothing"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "convertAllData": false,
        "sourceKey": "nothing",
        "options": {
          "fileName": "empty.dat",
          "mimeType": "text/plain",
          "useRawData": true
        }
      },
      "name": "Move Binary Data",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "Move Binary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

That actually works well @MutedJam, Using that example I have put together a more complete example.

We list the files, Check if it is .dat and if it is check for 0 size we then either make an empty binary file and save it or download it from the SFTP server.

Example Workflow
{
  "name": "FTP",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -570,
        170
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "nothing"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        30,
        10
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "convertAllData": false,
        "sourceKey": "nothing",
        "options": {
          "fileName": "={{$json[\"name\"]}}",
          "mimeType": "text/plain",
          "useRawData": true
        }
      },
      "name": "Move Binary Data",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        200,
        10
      ]
    },
    {
      "parameters": {
        "protocol": "sftp",
        "path": "={{$json[\"path\"]}}"
      },
      "name": "FTP",
      "type": "n8n-nodes-base.ftp",
      "typeVersion": 1,
      "position": [
        200,
        -160
      ],
      "alwaysOutputData": false,
      "credentials": {
        "sftp": {
          "id": "15",
          "name": "SFTP"
        }
      },
      "continueOnFail": true
    },
    {
      "parameters": {
        "protocol": "sftp",
        "operation": "list",
        "path": "/home/n8n/files/"
      },
      "name": "FTP1",
      "type": "n8n-nodes-base.ftp",
      "typeVersion": 1,
      "position": [
        -390,
        170
      ],
      "credentials": {
        "sftp": {
          "id": "15",
          "name": "SFTP"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"path\"]}}",
              "operation": "endsWith",
              "value2": ".dat"
            }
          ]
        }
      },
      "name": "IF .dat",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -200,
        170
      ]
    },
    {
      "parameters": {},
      "name": "NoOp1",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -200,
        350
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$json[\"size\"]}}",
              "operation": "notEqual"
            }
          ]
        }
      },
      "name": "IF1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -190,
        -20
      ]
    },
    {
      "parameters": {
        "fileName": "=/home/node/.n8n/{{$json[\"name\"]}}"
      },
      "name": "Write Binary File",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        400,
        -110
      ]
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "Move Binary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FTP": {
      "main": [
        [
          {
            "node": "Write Binary File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start": {
      "main": [
        [
          {
            "node": "FTP1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FTP1": {
      "main": [
        [
          {
            "node": "IF .dat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF .dat": {
      "main": [
        [
          {
            "node": "IF1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF1": {
      "main": [
        [
          {
            "node": "FTP",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move Binary Data": {
      "main": [
        [
          {
            "node": "Write Binary File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": 31
}
2 Likes

I have a complex workflow and before the files are downloaded i managed to add a new line to empty files with a bash script so that the ftp node does not produce that error for the time being.

Thank you.

2 Likes

Thank you i will look into it too. Great!