lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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.