Ajustado para subir arquivos
This commit is contained in:
@@ -79,11 +79,12 @@ local function getConfig()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.Upload()
|
function M.Upload()
|
||||||
|
|
||||||
getConfig()
|
getConfig()
|
||||||
local current_buffer_path = vim.api.nvim_buf_get_name(0)
|
local current_buffer_path = vim.api.nvim_buf_get_name(0)
|
||||||
local directoryTemp = directory
|
local directoryTemp = directory
|
||||||
|
|
||||||
-- message.warn("Send file ... Wait")
|
message.warn("Send file ... Wait")
|
||||||
|
|
||||||
if not directoryTemp:match("/$") then
|
if not directoryTemp:match("/$") then
|
||||||
directoryTemp = directoryTemp .. "/"
|
directoryTemp = directoryTemp .. "/"
|
||||||
@@ -97,36 +98,23 @@ function M.Upload()
|
|||||||
|
|
||||||
local remotePath = config.remote_path .. relative_path
|
local remotePath = config.remote_path .. relative_path
|
||||||
|
|
||||||
local ftp_script = string.format([[
|
local command = string.format(
|
||||||
open %s
|
'curl -T "%s" ftp://%s/%s --user "%s:%s" > /dev/null 2>&1',
|
||||||
user %s %s
|
current_buffer_path, config.host, remotePath, config.user, config.password)
|
||||||
put %s %s
|
|
||||||
bye
|
|
||||||
]], config.host, config.user, config.password, current_buffer_path, remotePath)
|
|
||||||
|
|
||||||
|
vim.loop.spawn("sh", {
|
||||||
local script_file = "ftp_commands.txt"
|
args = { "-c", command },
|
||||||
local file = io.open(script_file, "w")
|
}, function(code, signal)
|
||||||
file:write(ftp_script)
|
if code == 0 then
|
||||||
file:close()
|
vim.schedule(function()
|
||||||
|
message.info("File uploaded successfully!")
|
||||||
local log_file = "/tmp/ftp_log.txt"
|
end)
|
||||||
|
|
||||||
local exit_code = os.execute(string.format("ftp -n < %s > %s 2>&1", script_file, log_file))
|
|
||||||
|
|
||||||
|
|
||||||
local log = io.open(log_file, "r")
|
|
||||||
local log_content = log:read("*a")
|
|
||||||
log:close()
|
|
||||||
|
|
||||||
if log_content:match("Error") or log_content:match("fail") then
|
|
||||||
message.error("Fail to upload file!" .. log_content)
|
|
||||||
else
|
else
|
||||||
message.success("File send successfully!")
|
vim.schedule(function()
|
||||||
|
message.error("File upload failed with exit code: " .. code)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
os.remove(script_file)
|
|
||||||
os.remove(log_file)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ M.warn = vim.schedule_wrap(function(fmt, ...)
|
|||||||
vim.notify(fmt:format(...), levels.WARN, { title = 'Sync FTP' })
|
vim.notify(fmt:format(...), levels.WARN, { title = 'Sync FTP' })
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--- @type fun(fmt: string, ...: string)
|
||||||
|
M.info = vim.schedule_wrap(function(fmt, ...)
|
||||||
|
vim.notify(fmt:format(...), vim.log.INFO, { title = 'Sync FTP' })
|
||||||
|
end)
|
||||||
|
|
||||||
--- @type fun(fmt: string, ...: string)
|
--- @type fun(fmt: string, ...: string)
|
||||||
M.error = vim.schedule_wrap(function(fmt, ...)
|
M.error = vim.schedule_wrap(function(fmt, ...)
|
||||||
vim.notify(fmt:format(...), vim.log.levels.ERROR, { title = 'Sync FTP' })
|
vim.notify(fmt:format(...), vim.log.levels.ERROR, { title = 'Sync FTP' })
|
||||||
@@ -18,7 +23,7 @@ M.error_once = vim.schedule_wrap(function(fmt, ...)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
M.success = vim.schedule_wrap(function(fmt, ...)
|
M.success = vim.schedule_wrap(function(fmt, ...)
|
||||||
vim.notify(fmt:format(...), levels.SUCCESS, { title = 'Sync FTP'})
|
vim.notify(fmt:format(...), vim.log.INFO, { title = 'Sync FTP'})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user