Hello,
I try to create a simple flow dedicated to delete empty folders every hours in a SFTP server directory.
I don't find a solution to setup this condition...
Does someone has an idea ?
Thank you
AF
Delete empty folders in a SFTP
- magnussandstrom
- Advanced member
- Posts: 559
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Delete empty folders in a SFTP
You should be able to use FTP recieve for this:
Server type: SFTP
Leave originals on server: No
Check every (minutes): 60
Server type: SFTP
Leave originals on server: No
Check every (minutes): 60
Re: Delete empty folders in a SFTP
Hello Magnus,
thank you for your answer.
But I don't want to touch the folders that contain files, or the files in the root directory...
I don't see how to do it...
thank you for your answer.
But I don't want to touch the folders that contain files, or the files in the root directory...
I don't see how to do it...
- magnussandstrom
- Advanced member
- Posts: 559
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Delete empty folders in a SFTP
Oh sorry I misread your original question. I think you need the scripting module to be able to create that feature within a Switch flow. Do you have that?
Re: Delete empty folders in a SFTP
Thank you Magnus, no problem !
Yes, I also thought it couldn't be that easy...
I have the scripting module, but I lack knowledge in development.
I have no idea how I could write this script...
Yes, I also thought it couldn't be that easy...
I have the scripting module, but I lack knowledge in development.
I have no idea how I could write this script...
Re: Delete empty folders in a SFTP
I think you should consider other options for customer file upload that also are a lot more safe.
There are a few connectors for such services on the App store, for example Smash. Look in the category "Communication"
It will need a web portal interface instead of FPT-clients but it will give you a more modern and safer way to receive files and you don't need the FTP anymore.
There are a few connectors for such services on the App store, for example Smash. Look in the category "Communication"
It will need a web portal interface instead of FPT-clients but it will give you a more modern and safer way to receive files and you don't need the FTP anymore.
- magnussandstrom
- Advanced member
- Posts: 559
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Delete empty folders in a SFTP
To OP’s defense, there is nothing inherently wrong with SFTP from a security perspective, it’s quite different from plain FTP and is generally considered secure when configured properly.jan_suhr wrote: ↑Wed Mar 04, 2026 3:38 pm I think you should consider other options for customer file upload that also are a lot more safe.
There are a few connectors for such services on the App store, for example Smash. Look in the category "Communication"
It will need a web portal interface instead of FPT-clients but it will give you a more modern and safer way to receive files and you don't need the FTP anymore.
That said, if we understood the full workflow and requirements, there might be alternative approaches that simplify the process and avoid the need for regularly cleaning up empty folders.
- magnussandstrom
- Advanced member
- Posts: 559
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Delete empty folders in a SFTP
Are you running the Switch server on Windows or Mac?
Re: Delete empty folders in a SFTP
One very big obstacle with FTP is that you don't get much Metadata from an FTP-upload. Maybe and order number if the uploader added that to the filename.magnussandstrom wrote: ↑Thu Mar 05, 2026 8:12 am To OP’s defense, there is nothing inherently wrong with SFTP from a security perspective, it’s quite different from plain FTP and is generally considered secure when configured properly.
That said, if we understood the full workflow and requirements, there might be alternative approaches that simplify the process and avoid the need for regularly cleaning up empty folders.
With a web portal you can get a lot of information for the job and making the uploaded file process through Switch all the way to the production unit.
- magnussandstrom
- Advanced member
- Posts: 559
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Delete empty folders in a SFTP
I built a small program (Windows only) to use in a Switch flow that you can try out if you want (at your own risk of course):
Download here: https://tinyurl.com/3jwyjpe8
Just edit these variables in the Run command-app and you are ready to go:
Info:
The --min-age-minutes parameter is for preventing the deletion of folders that just have been created. But if mtime is not provided by the SFTP server you need to set it to 0 for it to work.
--root "/" means the root for the specific user, if you want you can set it to another directory like --root "/subfolder1/myfolder"
To run the check every 60 min I would suggest to add the Switch app FireStarter in the beginning of the flow and set it to 60 min.
The log folder is just a suggestion and can of course be deleted if you want to.
It works good for me, but please try on a test root folder first to ensure that the behaviour is what you are looking for.
Download here: https://tinyurl.com/3jwyjpe8
Just edit these variables in the Run command-app and you are ready to go:
Code: Select all
"C:\yourpath\cleanup-sftp.exe" --host sftp.server.com --user username --password "password" --root "/" --min-age-minutes 1The --min-age-minutes parameter is for preventing the deletion of folders that just have been created. But if mtime is not provided by the SFTP server you need to set it to 0 for it to work.
--root "/" means the root for the specific user, if you want you can set it to another directory like --root "/subfolder1/myfolder"
To run the check every 60 min I would suggest to add the Switch app FireStarter in the beginning of the flow and set it to 60 min.
The log folder is just a suggestion and can of course be deleted if you want to.
It works good for me, but please try on a test root folder first to ensure that the behaviour is what you are looking for.