FTP Upload overwrite

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
seraphyn
Posts: 2
Joined: 26 Sep 2013 10:08
Contact:

FTP Upload overwrite

Post by seraphyn » 26 Sep 2013 10:13

I created a FTP upload from the DCIM folder to my Server.
Did is with /storage/sdcard0/DCIM/Camera/* because I will not like to have a subfolder on my FTP.
Login everything works, but it uploads all files and overwrites the existing ones.
I need the possiblity to not overwrite existing ones, who should this could be done?

Was one reason for me to buy this app :(

Greetings Chris

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: FTP Upload overwrite

Post by Martin » 27 Sep 2013 07:55

Hi Chris,

By design the FTP action overwrites existing files. I already have an item on my todo list to skip existing files (with same size and/or timestamp) but it will probably take some time until I have the time to implement this feature.

In this case it should be possible to achieve something similar using two flows.
The first flow detects when a new photo is created and adds the name of the picture to a list of files to upload.
A second flow uploads all files in this list to your FTP server once a day and then clears the list.

Picture Detector Flow
-trigger File Observer: /storage/emulated/0/DCIM/Camera on events Subfile created
-action Script: global_new_pictures = addElement(global_new_pictures, registered_path + "/" + path);

The trigger executes the flow whenever a new file is created in the pictures folder. The trigger might be executed too many times on some devices when the camera app stores the picture to a temporary file first.
The trigger supplies two variables to the flow: registered_path contains the path configured in the trigger (for example /storage/emulated/0/DCIM/Camera), path contains the name of the new file (for example IMG_20130927_081000.jpg).
The script concatenates both variables to create an absolute path to the file (for example /storage/emulated/0/DCIM/Camera/IMG_20130927_081000.jpg) and adds the name to a global list called global_new_pictures.

Picture Uploader Flow
-trigger Time: everyday 20:00
-action FTP Upload Files: ftp:... set the field local paths to {global_new_pictures,listformat,comma}
-action Script: global_new_pictures = null;

This flow is executed once a day. It takes the list containing the new pictures, formats the list to a comma separated list and uploads the files to your FTP server. The script action clears the global list when the files have been uploaded.


German object names:

Picture Detector Flow
-trigger Datei Überwacher: /storage/emulated/0/DCIM/Camera bei Ereignis Unterdatei erstellt
-action Script: global_new_pictures = addElement(global_new_pictures, registered_path + "/" + path);

Picture Uploader Flow
-trigger Zeit: jeden Tag 20:00
-action FTP Dateien uploaden: ftp:... gib im Feld Lokale Dateipfade folgenden Wert ein: {global_new_pictures,listformat,comma}
-action Script: global_new_pictures = null;


Regards,
Martin

User avatar
seraphyn
Posts: 2
Joined: 26 Sep 2013 10:08
Contact:

Re: FTP Upload overwrite

Post by seraphyn » 27 Sep 2013 11:38

Thank you, this is more that a user could wish from a developer.
I try to get some spare time and I'll do it, and of course share.
I think some other user will need this of course too

Thanks Martin and keep up the good work
Christian

eegroove
Posts: 1
Joined: 19 Nov 2013 20:46

Re: FTP Upload overwrite

Post by eegroove » 20 Nov 2013 22:56

Thank you!
Great Tool. Great Script.

mtbx
Posts: 1
Joined: 25 Dec 2018 20:52

Re: FTP Upload overwrite

Post by mtbx » 26 Dec 2018 15:22

Let me bring up this quite old topic here...

The script works great and I use it to copy the photos I have taken during the day on my NAS at home. As a newbee to Automagic it took me less than fiteen minutes to set everything up and change the trigger from a daily routine to a trigger when my phone connects to my wifi at home. Also it is super fast. Big thanks for the script !

I would also like to use this script to sync the videos I have recorded. But with the existing trigger in the "Picture Detector Flow" only a temporary path without filename is stored in the global variable when I record the video. I also tried the alternate trigger "Writable file closed" but still only the temporary directory is stored there.

Does anyone of you has a hint for me how to solve this? Or is there any new possibility since 2013 how to perforn FTPS or SFTP copy/backup?

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: FTP Upload overwrite

Post by Desmanto » 27 Dec 2018 06:30

With video, it is quite difficult, as you need to know when the video file writing stop. I found out that a lot of temporary file writing happen. Probably the best way to do it is to keep a list of file with its datetime. Then sync only the change, probably periodically or on manual trigger basis.

You can also use trigger App Task ended, to detect when the camera app has been closed, wait for certain time. List all the file in the phone and FTP server. Use removeAllElements to remove all existing files in the FTP, so only leaving the new videos which haven't been synced yet. Upload only those unsynced videos.

Trigger File Observer with so many events ticked, can freeze Automagic; especially when you have abused using your glovar lavishly, as I used to do in the past. I will prefer to use other trigger when possible, or only activate the flow for certain period/condition. Check the similar thread for Trigger File observer : viewtopic.php?f=5&t=6937
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply