luacrul类库-ftp问题分析/解决

问题:使用smart_pub.kkf2中的 function t.upload(sftpTab) 函数ftp上传报错;

curl-error1.jpg

改函数使用了 LuaCURL库函数,网上先了解一下:

LuaCURL is Lua 5.x compatible module providing Internet browsing capabilities based on the CURL library. The module interface follows strictly the CURl architecture and is very easy to use if the programmer has already experience with CURL. The only LuaCURL luaopen_luacurl public function register itself to the Lua context defining a namespace curl with one constructor and some utility functions.

查了其他网站资料,对LUA的类库解释的很少,官网英文且解释的不全面,不容易理解,
所以参考php的libcurl库说明,语言不同,类似可以参考;
分析报错信息,初步理解为文件目录不存在,或者创建失败;定位:


curl_website.jpg
curl_csharp.jpg

查看系统关键源码设置:
源码【顺便在源码上加了注释,便于理解其他参数】

    c:setopt(curl.OPT_UPLOAD, true)    --TRUE 准备上传。
    c:setopt(curl.OPT_VERBOSE, true)   --TRUE 会输出所有的信息,写入到STDERR,或在CURLOPT_STDERR中指定的文件。
    c:setopt(curl.OPT_USERPWD, userpwd)  --传递一个连接中需要的用户名和密码,格式为:"[username]:[password]"。
    c:setopt(curl.OPT_URL, optUrl)   -- 需要获取的 URL 地址,也可以在curl_init() 初始化会话的时候。
    c:setopt(curl.OPT_SSL_VERIFYPEER, false)  --FALSE 禁止 cURL 验证对等证书(peer's certificate)。要验证的交换证书可以在 CURLOPT_CAINFO 选项中设置,或在 CURLOPT_CAPATH中设置证书目录。
    c:setopt(curl.OPT_READDATA, f)  -- custom pointer passed to the read callback
    c:setopt(curl.OPT_WRITEDATA, ret)  --custom pointer passed to the write callback
    c:setopt(curl.OPT_SSH_AUTH_TYPES, curl.SSH_AUTH_PASSWORD)  --A bitmask consisting of one or more ofCURLSSH_AUTH_PUBLICKEY, CURLSSH_AUTH_PASSWORD,CURLSSH_AUTH_HOST, CURLSSH_AUTH_KEYBOARD. Set toCURLSSH_AUTH_ANY to let libcurl pick one.
    c:setopt(curl.OPT_WRITEFUNCTION, function(tab, buffer)  --回调函数名。该函数应接受两个参数。第一个是 cURL resource;第二个是要写入的数据字符串。数 据必须在函数中被保存。 函数必须准确返回写入数据的字节数,否则传输会被一个错误所中 断。

新增设置

    c:setopt(curl.OPT_FTP_CREATE_MISSING_DIRS, true)

测试问题解决:


curl_sucess.jpg

还好之前使用过curl工具模拟webservice、rest客户端报文测试,相对通用理解一些,curllib库还有很多功能可能总结学习;

参考 http://luaforge.net/projects/luacurl/
http://underpop.free.fr/l/lua/luacurl/
https://www.cnblogs.com/endv/p/8433889.html

你可能感兴趣的:(luacrul类库-ftp问题分析/解决)