Avatar of travisryan
travisryan
Flag for United States of America asked on

Lua FTP upload issues

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.

Our Products:
Canon PowerShot GLPH17015
FlashAir W-03, 16GB running latest firmware
Windows Network

Here is where I pulled the original code from:
https://bitbucket.org/harbortronics/flashair-ftp-upload/downloads/

The card is working, I was able to not only plug it into my computer and view files, but also my iPhone with an OTG adapter.

For the most part, this script is based on 3 files: CONFIG, ftpupload.lua, and settings.lua

The config file is where most of the work happens in the foreground, here is my CONFIG:
**********
[Vendor]

CIPATH=/DCIM/100__TSB/FA000001.JPG
APPNAME=flashair
APPMODE=5
APPSSID=*WIRELESS NETWORK*
APPNETWORKKEY=*WIRELESS NETWORK PASSWORD*
VERSION=FA9CAW3AW3.00.01
CID=02544d535731364740d03b5479010601
PRODUCT=FlashAir
VENDOR=TOSHIBA


MASTERCODE=accf856bbe74
LOCK=1

UPLOAD=1
STA_RETRY_CT=0
LUA_SD_EVENT=/ftpupload.lua

Open in new window

**********

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 exist

function exists(path)
    if lfs.attributes(path) then
        return true
    else
        return false
    end
end

function is_uploaded(path)
    local hash = fa.hash("md5", path, "")
    return exists(lockdir .. hash)
end

function set_uploaded(path)
    local hash = fa.hash("md5", path, "")
    local file = io.open(lockdir .. hash, "w")
    file:close()
end

function 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)
end

function 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()
end

function 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
    end
end

-- wait for wifi to connect
while string.sub(fa.ReadStatusReg(),13,13) ~= "a" do
    print("Wifi not connected. Waiting...")
    sleep(1000)
end
walk_directory(folder)

Open in new window

**********

And here is the settings.lua code for the ftpupload.lua script:
-- FTP Settings --
logfile   = "/FTPLog.txt"     -- Where to log output on the FA
folder    = "/DCIM"           -- What folder to upload files from
server    = "qualitypic.example.com"                -- The FTP server's IP
serverDir = "/"                -- The path on the FTP server to use.
user      = "FAupload"                -- FTP username
passwd    = "********"                -- FTP password
delete_after_upload = false

Open in new window

FTPScripting Languages* Camera* Toshiba* Lua

Avatar of undefined
Last Comment
travisryan

8/22/2022 - Mon
David Johnson, CD

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.
ASKER CERTIFIED SOLUTION
David Johnson, CD

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
travisryan

ASKER
According to the logs, its getting on the server but not using the authentication credentials I provided:

#Software: Microsoft Internet Information Services 8.5
#Version: 1.0
#Date: 2017-04-04 20:16:51
#Fields: time c-ip cs-method cs-uri-stem sc-status sc-win32-status
20:16:51 10.1.80.180 ControlChannelOpened - - 0
20:16:51 10.1.80.180 AUTH TLS 534 5
20:16:51 10.1.80.180 AUTH SSL 534 5
20:16:51 10.1.80.180 USER +My user name+ 331 0
20:16:51 10.1.80.180 PASS *** 230 0
20:16:51 10.1.80.180 SYST - 215 0
20:16:51 10.1.80.180 FEAT - 211 0
20:16:51 10.1.80.180 OPTS UTF8+ON 200 0
20:16:51 10.1.80.180 PWD - 257 0
20:16:51 10.1.80.180 TYPE I 200 0
20:16:51 10.1.80.180 PASV - 227 0
20:16:52 10.1.80.180 DataChannelOpened - - 0
20:16:52 10.1.80.180 DataChannelClosed - - 0
20:16:52 10.1.80.180 LIST - 226 0
20:16:52 10.1.80.180 MDTM .DS_Store 213 0
20:17:22 10.1.80.180 ControlChannelOpened - - 0
20:17:22 10.1.80.180 AUTH TLS 534 5
20:17:22 10.1.80.180 AUTH SSL 534 5
20:17:22 10.1.80.180 USER +My user name+ 331 0
20:17:22 10.1.80.180 PASS *** 230 0
20:17:22 10.1.80.180 SYST - 215 0
20:17:22 10.1.80.180 FEAT - 211 0
20:17:22 10.1.80.180 OPTS UTF8+ON 200 0
20:17:22 10.1.80.180 PWD - 257 0
20:17:22 10.1.80.180 TYPE I 200 0
20:17:22 10.1.80.180 PASV - 227 0
20:17:22 10.1.80.180 DataChannelOpened - - 0
20:17:22 10.1.80.180 DataChannelClosed - - 0
20:17:22 10.1.80.180 LIST - 226 0
20:17:22 10.1.80.180 MDTM .DS_Store 213 0
20:18:58 10.1.80.180 ControlChannelClosed - - 258
20:19:28 10.1.80.180 ControlChannelClosed - - 258

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
travisryan

ASKER
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.
travisryan

ASKER
Project abandoned, advice was solid.