@ -1,6 +1,7 @@
local DocumentRegistry = require ( " document/documentregistry " )
local ftp = require ( " socket.ftp " )
local ltn12 = require ( " ltn12 " )
local util = require ( " util " )
local url = require ( " socket.url " )
local FtpApi = {
@ -15,27 +16,28 @@ function FtpApi:generateUrl(address, user, pass)
if pass ~= " " then
colon_sign = " : "
end
local replace = " :// " .. user .. colon_sign .. pass .. at_sign
local generated_url = string.gsub ( address , " :// " , replace )
local generated_url = " ftp:// " .. user .. colon_sign .. pass .. at_sign .. address : gsub ( " ftp:// " , " " )
return generated_url
end
function FtpApi : nlst( u )
function FtpApi : ftpGet( u , command )
local t = { }
local p = url.parse ( u )
p.command = " nlst "
p.user = util.urlDecode ( p.user )
p.password = util.urlDecode ( p.password )
p.command = command
p.sink = ltn12.sink . table ( t )
local r , e = ftp.get ( p )
return r and table.concat ( t ) , e
end
function FtpApi : listFolder ( address_path , folder_path )
function FtpApi : listFolder ( address_path , folder_path )
local ftp_list = { }
local ftp_file = { }
local type
local extension
local file_name
local ls_ftp = self : nlst( address_path )
local ls_ftp = self : ftpGet( address_path , " nlst " )
if ls_ftp == nil then return false end
if folder_path == " / " then
folder_path = " "
@ -79,12 +81,10 @@ function FtpApi:listFolder(address_path,folder_path)
return ftp_list
end
function FtpApi : downloadFile ( file_path )
return ftp.get ( file_path .. " ;type=i " )
end
function FtpApi : delete ( file_path )
local p = url.parse ( file_path )
p.user = util.urlDecode ( p.user )
p.password = util.urlDecode ( p.password )
p.argument = string.gsub ( p.path , " ^/ " , " " )
p.command = " dele "
p.check = 250