# Can not get files via sftp

**URL:** <https://discourse.nodered.org/t/can-not-get-files-via-sftp/61633>\
**Category:** General\
**Created:** [22 April 2022 09:03 UTC](https://discourse.nodered.org/t/can-not-get-files-via-sftp/61633 "2022-04-22T09:03:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [22 April 2022 09:03 UTC](https://discourse.nodered.org/t/can-not-get-files-via-sftp/61633/1 "2022-04-22T09:03:50Z")

</div>

Hi,

I'm trying to get all files from a folder on a server via sftp and download them into a specific local folder.  
If possible, I'd only like to download those files that start with XYC.

I tried the following flow, but am only getting the buffer of those files. How would I either set the local folder where the files should be stored or use the "write file" function to store all files? (there will always be multiple files, so I can not set a filename in the "write file" function)

```auto
[
    {
        "id": "e72b337e9c7f6a48",
        "type": "debug",
        "z": "a69da9d2e0a258af",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1130,
        "y": 120,
        "wires": []
    },
    {
        "id": "8c9f3d4c732120fe",
        "type": "sftp in",
        "z": "a69da9d2e0a258af",
        "name": "",
        "sftp": "",
        "operation": "get",
        "filename": "",
        "localFilename": "",
        "workdir": "/root/transfer/in/",
        "x": 930,
        "y": 240,
        "wires": [
            [
                "e72b337e9c7f6a48"
            ]
        ]
    },
    {
        "id": "e44b9fe017c1de25",
        "type": "change",
        "z": "a69da9d2e0a258af",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "\"/sample\" & msg.payload.name",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 760,
        "y": 240,
        "wires": [
            [
                "8c9f3d4c732120fe"
            ]
        ]
    },
    {
        "id": "99ff4c9b2c5eafdb",
        "type": "debug",
        "z": "a69da9d2e0a258af",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.name",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 320,
        "wires": []
    },
    {
        "id": "dfec3f0ea75af213",
        "type": "split",
        "z": "a69da9d2e0a258af",
        "name": "Split message to file names",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 500,
        "y": 260,
        "wires": [
            [
                "99ff4c9b2c5eafdb",
                "e44b9fe017c1de25"
            ]
        ]
    },
    {
        "id": "c8dc3ac050ba705d",
        "type": "sftp in",
        "z": "a69da9d2e0a258af",
        "name": "",
        "sftp": "",
        "operation": "list",
        "filename": "",
        "localFilename": "",
        "workdir": "/sample/",
        "x": 290,
        "y": 260,
        "wires": [
            [
                "dfec3f0ea75af213"
            ]
        ]
    },
    {
        "id": "caa682de3c9ad73f",
        "type": "inject",
        "z": "a69da9d2e0a258af",
        "name": "",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 110,
        "y": 260,
        "wires": [
            [
                "c8dc3ac050ba705d"
            ]
        ]
    }
]

```

Thanks!

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [22 April 2022 10:16 UTC](https://discourse.nodered.org/t/can-not-get-files-via-sftp/61633/2 "2022-04-22T10:16:29Z")

</div>

Which sftp node are you using (I'll need to load it in to test it out)

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [22 April 2022 10:30 UTC](https://discourse.nodered.org/t/can-not-get-files-via-sftp/61633/3 "2022-04-22T10:30:01Z")

</div>

Hi,

I'm using node-red-contrib-better-sftp

Thanks

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 April 2022 10:45 UTC](https://discourse.nodered.org/t/can-not-get-files-via-sftp/61633/4 "2022-04-22T10:45:38Z")

</div>

Can you attach a debug node to the output (set to "show complete message") & and show us the results from the sftp node? Expand the properies of the debug `msg` - ideally we would see where the "files" and "file names" are presented in the msg.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [22 April 2022 10:52 UTC](https://discourse.nodered.org/t/can-not-get-files-via-sftp/61633/5 "2022-04-22T10:52:26Z")

</div>

> [@smitterer](#):
>
> node-red-contrib-better-sftp

Right - tried it out and AFACS the problem is the sftp in node is not passing thru the msg.payload.name so that you can then use it ☹

Workaround (but might be dodgy/unacceptable to you) is to copy the name to a flow variable and then use it later on in the flow to write the filename

But you'd either have to rate limit slow enough to ensure file has been downloaded from the website (which of course might not work 100% of time)

Or complicate the flow with a gate node that fed with status of what is happening further along the flow

That's all I can come with for now

[edit] tried setting topic to the filename but even that gets filtered out ☹

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [22 April 2022 11:06 UTC](https://discourse.nodered.org/t/can-not-get-files-via-sftp/61633/6 "2022-04-22T11:06:42Z")

</div>

There are a few sftp nodes so one of them might work better and not do the filtering?

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [24 April 2022 20:07 UTC](https://discourse.nodered.org/t/can-not-get-files-via-sftp/61633/7 "2022-04-24T20:07:35Z")

</div>

Hi,

I'm now using node-red-contrib-sftpco and this one works.

Thanks

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [25 April 2022 06:29 UTC](https://discourse.nodered.org/t/can-not-get-files-via-sftp/61633/8 "2022-04-25T06:29:14Z")

</div>

Good find 🙂  
I tested it myself and it worked lovely except for the fact that my remote test folder I'm using contains sub-folders and I can't work out how to ignore them

_Apart from trying to detect whether the end of the filename contains .xxxxx_ 🙂

The better-sftp node does provide a property of type which I was previously using to filter out sub-folders

End result is the get node only gets the 1st file entry and then stops processing on any more requests as the 2nd one is a folder ☹

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/ed77aa1183523d946bb135ac46a429753f7c9d14.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/f/4fcd2e760f06a8335e7f6c80b559c097215b2642.png)

The node info on github/npm implies we can filter directory names but I can't actually work out how to do it ☹

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [9 May 2022 06:30 UTC](https://discourse.nodered.org/t/can-not-get-files-via-sftp/61633/9 "2022-05-09T06:30:03Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
