提问人:Andrex Youtube 提问时间:4/15/2023 更新时间:4/15/2023 访问量:51
Flashair与LUA_SD_EVENT问题(文件未使用FTP传输)
Flashair issue with LUA_SD_EVENT (Files are not transfering using FTP)
问:
ftpupload.lua 文件未运行或代码中存在问题。我的FlashAir Wi-Fi sd卡需要它。
我之前用过这个代码:
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)
但后来我发现了一个教程,其中的代码略有不同,所以我决定使用它:
--[[
FTPUpload.lua
Copyright (c) 2019 Toshiba Memory Corporation.
All sample code on this page is licensed under BSD 2-Clause License
https://github.com/FlashAirDevelopers/LuaTutorial/blob/master/LICENSE
]]
local logfile = "/FTPLog.txt" -- Log file created in FlashAir
local folder = "/DCIM" -- Folder to upload file is located
local server = "192.168.50.178" -- IP address of FTP server
local serverDir = "/home/andrexserver" -- FTP server upload folder
local user = "andrexserver" -- FTP user name
local passwd = "********" -- FTP password
-- Assemble our FTP command string
-- example: "ftp://user:[email protected]/LuaTutorial"
local ftpstring = "ftp://"..user..":"..passwd.."@"..server..serverDir
-- Open the log file
local outfile = io.open(logfile, "w")
-- Write a header
outfile:write("File list: \n")
-- For each file in folder...
for file in lfs.dir(folder) do
-- Get that file's attributes
attr = lfs.attributes(folder .. "/" .. file)
print( "Found "..attr.mode..": " .. file )
-- Don't worry about directories (yet)
if attr.mode == "file" then
--Attempt to upload the file!
--ex ftp("put", "ftp://user:[email protected]/LuaTutorial/test.jpg", "Upload/test.jpg")
response = fa.ftp("put", ftpstring .. "/" .. file, folder .. "/" .. file)
--Check to see if it worked, and log the result!
if response ~= nil then
print("Success!")
outfile:write("" .. file .. "... Success!\n")
else
print("Fail :(")
outfile:write("" .. file .. "... Fail :(\n")
end
end
end
--Close our log file
outfile:close()
但它仍然不起作用 这是我的 CONFIG 文件:
[Vendor]
CIPATH=/DCIM/100__TSB/FA000001.JPG
VERSION=F15DBW3BW4.00.04
PRODUCT=FlashAir
VENDOR=TOSHIBA
APPMODE=5
APPSSID=KBELY 2G
APPNETWORKKEY=*********
DELCGI=/thumbnail.cgi,/config.cgi
APPNAME=WI-FI SD-CARD
UPLOAD=1
WEBDAV=0
MASTERCODE=accf856bbe74
LOCK=1
UPLOAD=1
STA_RETRY_CT=0
LUA_SD_EVENT=/ftpupload.lua
github上有教程代码: 我用过的 https://github.com/FlashAirDevelopers/LuaTutorial 代码: https://github.com/FlashAirDevelopers/LuaTutorial/blob/master/lua_tutorial_4/FTPUpload.lua 我真的不知道该怎么办。
答: 暂无答案
下一个:绕过旋转门蟒硒
评论