As you can see, the CONFIG points to the ftpupload.lua script, so here is my script:
**********
require("Settings")local ftpstring = "ftp://"..user..":"..passwd.."@"..server.."/"..serverDir.."/"local lockdir = "/uploaded/" -- trailing slash required, and folder must already existfunction exists(path) if lfs.attributes(path) then return true else return false endendfunction is_uploaded(path) local hash = fa.hash("md5", path, "") return exists(lockdir .. hash)endfunction set_uploaded(path) local hash = fa.hash("md5", path, "") local file = io.open(lockdir .. hash, "w") file:close()endfunction delete(path) -- Both of the following methods cause the next photo to be lost / not stored. fa.remove(path) -- fa.request("http://127.0.0.1/upload.cgi?DEL="..path)endfunction upload_file(folder, file) local path = folder .. "/" .. file -- Open the log file local outfile = io.open(logfile, "a") outfile:write(file .. " ... ") local response = fa.ftp("put", ftpstring..file, path) --Check to see if it worked, and log the result! if response ~= nil then print("Success!") outfile:write(" Success!\n") set_uploaded(path) if delete_after_upload == true then print("Deleting " .. file) outfile:write("Deleting " .. file .. "\n") sleep(1000) delete(path) sleep(1000) end else print(" Fail ") outfile:write(" Fail\n") end --Close our log file outfile:close()endfunction walk_directory(folder) -- Recursively iterate filesystem for file in lfs.dir(folder) do local path = folder .. "/" .. file local attr = lfs.attributes(path) print( "Found "..attr.mode..": " .. path ) if attr.mode == "file" then if not is_uploaded(path) then upload_file(folder, file) else print(path .. " previously uploaded, skipping") end elseif attr.mode == "directory" then print("Entering " .. path) walk_directory(path) end endend-- wait for wifi to connectwhile string.sub(fa.ReadStatusReg(),13,13) ~= "a" do print("Wifi not connected. Waiting...") sleep(1000)endwalk_directory(folder)
And here is the settings.lua code for the ftpupload.lua script:
-- FTP Settings --logfile = "/FTPLog.txt" -- Where to log output on the FAfolder = "/DCIM" -- What folder to upload files fromserver = "qualitypic.example.com" -- The FTP server's IPserverDir = "/" -- The path on the FTP server to use.user = "FAupload" -- FTP usernamepasswd = "********" -- FTP passworddelete_after_upload = false
We have a camera with a Toshiba Flash Air card and we are trying to upload pictures via FTP to a network drive with a lua script running on the card. AND what is happening when you take a picture does it then initiate the ftp upload?
travisryan
ASKER
No, as far as I can tell it does not even initiate the upload. I kept an eye on the folder the card pointed to and nothing appeared in the folder. I set the camera down next to the router for about an hour and nothing came through.
I was able to get it connected to the server after multiple attempts. I am now having issues getting it to actually upload all of the media. Its uploading one picture and ending the queue - from what it appears. Nothing showed in the logs other than connect, with credentials, upload, and close connection.