Is it possible to do an FTP put via LUUP?

I have Tasker on an android phone. I want Vera to be able to send something to the android phone to have it execute a task. Tasker cannot listen on a socket. But, it can monitor for file changes and then execute a task when the file is changed. I can install an FTP server on the phone. What I want to do is create a virtual switch called “Police Scanner”, a scene for when it turns on, and then when the LUUP code for it uploads a file called ScannerOn.tmp, Tasker will see the changed modification date and execute a task that starts Scanner Radio playing my local police scanner stream. And I’ll have another one for shutting it off.

If I do something like “put /dev/null /sdcard/TaskerFiles/ScannerOn.tmp”, it will create (or modify) a 0 byte file called ScannerOn.tmp.

Unless someone can think of another way to have Vera send data over the network to the android phone that I can use to execute tasks. I want to do this on the local network, I do not want to rely on an internet connection for this to work like some of the Android “notify” programs require.

Thoughts?

Turns out that it is possible:

[code]-- load the ftp support
local ftp = require(“socket.ftp”)

f, e = ftp.put(“ftp://vera:password@10.32.32.50:2121/ScannerOn.tmp”,
“randomtextblablabla”)[/code]

What does the “f, e” do? I grabbed this code from a LUA forum.

I ran this through the test LUA code thing, and it said “command failed”. But, it created the file on the android phone and put that text in it. So it works.

The only problem is, the “File Modified” event on Tasker is not triggering for me at all. I’ve added different text thinking that maybe it was actually looking at content instead of timestamp, and it still doesn’t work. I’ve also tried the “File Opened” event and that doesn’t trigger either. Very strange. I also tried putting in the full path to the file using /mnt/sdcard/vera/ScannerOn.tmp, and that didn’t help either.

f and e are variables that tell you if the PUT worked.

f is 1 on success. If so, e is not useful.

f is nil on failure. If so, e is an error string that tells you why the PUT failed.

See: LuaSocket: FTP support

So would a “return f” at the end of this prevent the test LUUP code thing from returning a Command Failed error?

Ah ha! Uploading a new file every time didn’t fire the Tasker event because it was deleting the old file first. I used the FTP append command and added to an existing file, and that works:

[code]local ftp = require(“socket.ftp”)
local ltn12 = require(“ltn12”)

f, e = ftp.put{
host = “10.32.32.50”,
port = “2121”,
user = “vera”,
password = “password”,
command = “appe”,
argument = “ScannerOn.tmp”,
source = ltn12.source.string(“z”)
}
return f
[/code]

Hi

Interesting stuff, following on the FTP theme and the code you have written, do you know what the code would be to take either a file or multiple files or a folder) from Vera and put it on a CIFS share on a NAS?

Unless im mistaken, this has potential to be used as a scheduled back up Scene?

Thanks

CIFS is complicated. A lot more than FTP. If you are looking for a scheduled backup of Vera to a NAS, you could do what I do and use rsync. Installing rsync on Vera is just a matter of installing the package (opkg install rsync). Installing rsync on the NAS is probably easy (Synology has a homebrew package). Then use cron to schedule it.

+1 on rsync. It’s super reliable, and only copies changes after the initial backup to reduce bandwidth and time.

Sent from my Galaxy Nexus using Tapatalk 2

Thanks all.

Just checked my NAS and it already has FTP on all shares too, so it sounds like i can avoid the more compex CIfS way.

So when you have time, how would the script need to change to pick up a file, folder etc and send it to my external NAS share?

Many Thanks

Does your NAS have ssh and rsync on it? I would not code this with LUUP. I would just write a cronjob and have the underlying OS on Vera do it that way. If you do it with LUUP, you have to write something that will recursively go through all of your directories and upload each file.

Vera has a built in backup function also, and it should be doing autobackups daily to cp.mios.com right now. You can also pull down an already packaged backup from the Setup->Backup page.

Creating your own backup mechanism is likely going to present problems when restoring. Why not just use the packaged stuff?

Hi signal15

Thanks again, I wanted to avoid using SSH or doing anything which involved me playing around on the ‘inside’ of Vera, so I was hoping there was a straight forward bit of code that would allow me to back something up via a LUA in a scene. But It sounds like it’s not as straight forward as it seemed from your piece of code up above…

Hi,

I tried installing rsync on vera3 using ‘opkg install rsync’. But it does not seem to recognize rsync

Unknown package ‘rsync’.
Collected errors:

  • opkg_install_cmd: Cannot install package rsync.

Any suggestions to install rsync or an alternative on vera3 would be very helpful.

Thanks

Before you can run “opkg install” you must run “opkg update”.

Thank you. That totally worked. \m/