Skip to content

Instantly share code, notes, and snippets.

@jie-meng
Last active June 4, 2017 10:51
Show Gist options
  • Select an option

  • Save jie-meng/6d6846e325b077c1c1c7a54caf73527f to your computer and use it in GitHub Desktop.

Select an option

Save jie-meng/6d6846e325b077c1c1c7a54caf73527f to your computer and use it in GitHub Desktop.
lua ftp using curl
local file_ext = require('file_ext')
local table_ext = require('table_ext')
local tmp_file = 'listfile.tmp.000'
function downloadDir(server, user, password, server_path, local_path)
if os.execute(string.format('curl -l "%s/%s/" --user %s:%s > %s', server, server_path, user, password, tmp_file)) then
local lines = file_ext.readLines(tmp_file)
util.pathRemove(tmp_file)
table_ext.foreach(lines, function (k, v)
local cmd = string.format('curl "%s/%s/%s" --user %s:%s -o "%s/%s"', server, server_path, v, user, password, local_path, v)
print(cmd)
if os.execute(cmd) then
print('<<< success >>>\n')
else
print('<<< fail >>>\n')
end
end)
end
print('done')
end
function uploadDir(server, user, password, server_path, local_path, func)
local files = file_ext.findFilesInDir(local_path, func)
table_ext.foreach(files, function (k, v)
local p, f = util.splitPathname(v)
local cmd = string.format('curl -T "%s/%s" --user %s:%s "%s/%s/"', local_path, f, user, password, server, server_path)
print(cmd)
if os.execute(cmd) then
print('<<< success >>>\n')
else
print('<<< fail >>>\n')
end
end)
print('done')
end
--uploadDir('ftp://192.168.0.103:2121', 'anonymous', 'anonymous', 'emu', 'testok')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment