[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lua-cURL How to upload a file?
- From: albert <albert_200200@...>
- Date: Mon, 04 Mar 2013 10:41:32 +0800
The example code in the project is in file ftpupload.lua:
require("cURL")
c=cURL.easy_init()
c:setopt_url("ftp://ftptest:secret0815@targethost/file.dat")
c:setopt_upload(1)
count=0
c:perform({readfunction=function(n)
count = count + 1
if (count < 10) then
return "Line " .. count .. "\n"
end
return nil
end})
print("Fileupload done")
However this example can't fulfill my requirement, I want to upload a
local exist file while not a trash file.
I change the readfunction to my code below:
c:perform({readfunction=function(n)
local datafilename = "mydatafile"
local fhandle = io.open(datafilename, "r")
local datafromfile = nil
if nil ~= fhandle then
datafromfile = fhandle:read("*all")
fhandle:close()
end
return datafromfile
end})
But my code didn't work. Hope I can find help here. Thanks in advance.