mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2025-12-20 02:59:20 +01:00
FTP hotfix; fixes #686
This commit is contained in:
parent
b9c5919acc
commit
283d0fca68
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
local GUI = require("GUI")
|
local GUI = require("GUI")
|
||||||
local event = require("Event")
|
local event = require("Event")
|
||||||
local filesystem = require("Filesystem")
|
local filesystem = require("Filesystem")
|
||||||
@ -22,7 +21,7 @@ network.modemTimeout = 2
|
|||||||
|
|
||||||
network.internetProxy = nil
|
network.internetProxy = nil
|
||||||
network.internetDelay = 0.05
|
network.internetDelay = 0.05
|
||||||
network.internetTimeout = 0.25
|
network.internetTimeout = 1
|
||||||
|
|
||||||
network.proxySpaceUsed = 0
|
network.proxySpaceUsed = 0
|
||||||
network.proxySpaceTotal = 1073741824
|
network.proxySpaceTotal = 1073741824
|
||||||
@ -127,11 +126,16 @@ local function FTPEnterPassiveModeAndRunCommand(commandSocketHandle, command, da
|
|||||||
FTPSocketWrite(commandSocketHandle, "PASV")
|
FTPSocketWrite(commandSocketHandle, "PASV")
|
||||||
|
|
||||||
local success, result = FTPSocketRead(commandSocketHandle)
|
local success, result = FTPSocketRead(commandSocketHandle)
|
||||||
if success then
|
if not success then
|
||||||
local digits = {result:match("Entering Passive Mode %((%d+),(%d+),(%d+),(%d+),(%d+),(%d+)%)")}
|
return false, result
|
||||||
if #digits == 6 then
|
end
|
||||||
local address, port = table.concat(digits, ".", 1, 4), tonumber(digits[5]) * 256 + tonumber(digits[6])
|
|
||||||
|
|
||||||
|
local digits = {result:match("Entering Passive Mode %((%d+),(%d+),(%d+),(%d+),(%d+),(%d+)%)")}
|
||||||
|
if #digits ~= 6 then
|
||||||
|
return false, "Entering passive mode failed: wrong address byte array. Socket response message was: " .. tostring(result)
|
||||||
|
end
|
||||||
|
|
||||||
|
local address, port = table.concat(digits, ".", 1, 4), tonumber(digits[5]) * 256 + tonumber(digits[6])
|
||||||
FTPSocketWrite(commandSocketHandle, command)
|
FTPSocketWrite(commandSocketHandle, command)
|
||||||
|
|
||||||
local dataSocketHandle = network.internetProxy.connect(address, port)
|
local dataSocketHandle = network.internetProxy.connect(address, port)
|
||||||
@ -146,39 +150,38 @@ local function FTPEnterPassiveModeAndRunCommand(commandSocketHandle, command, da
|
|||||||
local success, result = FTPSocketRead(dataSocketHandle)
|
local success, result = FTPSocketRead(dataSocketHandle)
|
||||||
dataSocketHandle.close()
|
dataSocketHandle.close()
|
||||||
|
|
||||||
if success then
|
return not not success, result
|
||||||
return true, result
|
|
||||||
else
|
|
||||||
return false, result
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return false, "Entering passive mode failed: wrong address byte array. Socket response message was: " .. tostring(result)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return false, result
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function FTPParseFileInfo(result)
|
local function FTPParseFileInfo(result)
|
||||||
local size, year, month, day, hour, minute, sec, type, name = result:match("Size=(%d+);Modify=(%d%d%d%d)(%d%d)(%d%d)(%d%d)(%d%d)(%d%d)[^;]*;Type=([^;]+);%s([^\r\n]+)")
|
local info = {}
|
||||||
if size then
|
|
||||||
return
|
for token in result:gmatch("[^; ]+") do
|
||||||
true,
|
local key, value = token:match("(.+)=(.+)")
|
||||||
name,
|
|
||||||
type == "dir",
|
if key then
|
||||||
tonumber(size),
|
key = key:lower()
|
||||||
os.time({
|
|
||||||
year = year,
|
if key == "size" or key == "sizd" then
|
||||||
day = day,
|
info["size"] = tonumber(value)
|
||||||
month = month,
|
elseif key == "modify" then
|
||||||
hour = hour,
|
info["modify"] = tonumber(value)
|
||||||
minute = minute,
|
elseif key == "type" then
|
||||||
sec = sec
|
info["isdir"] = not not value:match("dir")
|
||||||
})
|
|
||||||
else
|
else
|
||||||
|
info[key] = value
|
||||||
|
end
|
||||||
|
else
|
||||||
|
info["filename"] = token
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not info["filename"] or info["isdir"] == nil then
|
||||||
return false, "File not exists"
|
return false, "File not exists"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return true, info["filename"], info["isdir"], info["size"] or 0, info["modify"] or 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local function FTPFileInfo(socketHandle, path, field)
|
local function FTPFileInfo(socketHandle, path, field)
|
||||||
@ -254,20 +257,22 @@ function network.connectToFTP(address, port, user, password)
|
|||||||
end
|
end
|
||||||
|
|
||||||
proxy.list = function(path)
|
proxy.list = function(path)
|
||||||
local success, result = FTPEnterPassiveModeAndRunCommand(socketHandle, "MLSD -a " .. path)
|
local success, result = FTPEnterPassiveModeAndRunCommand(socketHandle, "MLSD " .. path)
|
||||||
if success then
|
|
||||||
|
if not success then
|
||||||
|
return nil, result
|
||||||
|
end
|
||||||
|
|
||||||
local list = FTPParseLines(result)
|
local list = FTPParseLines(result)
|
||||||
for i = 1, #list do
|
for i = 1, #list do
|
||||||
local success, name, isDirectory = FTPParseFileInfo(list[i])
|
local success, name, isDirectory = FTPParseFileInfo(list[i])
|
||||||
|
|
||||||
if success then
|
if success then
|
||||||
list[i] = name .. (isDirectory and "/" or "")
|
list[i] = name .. (isDirectory and "/" or "")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return list
|
return list
|
||||||
else
|
|
||||||
return {}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
proxy.isDirectory = function(path)
|
proxy.isDirectory = function(path)
|
||||||
@ -281,7 +286,7 @@ function network.connectToFTP(address, port, user, password)
|
|||||||
|
|
||||||
proxy.lastModified = function(path)
|
proxy.lastModified = function(path)
|
||||||
local success, result = check(FTPFileInfo(socketHandle, path, "lastModified"))
|
local success, result = check(FTPFileInfo(socketHandle, path, "lastModified"))
|
||||||
if success then
|
if success and result ~= false then
|
||||||
return result
|
return result
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
@ -328,6 +333,10 @@ function network.connectToFTP(address, port, user, password)
|
|||||||
end
|
end
|
||||||
|
|
||||||
proxy.close = function(fileHandle)
|
proxy.close = function(fileHandle)
|
||||||
|
if not fileHandles[fileHandle] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
filesystemProxy.close(fileHandle)
|
filesystemProxy.close(fileHandle)
|
||||||
|
|
||||||
if fileHandles[fileHandle].needUpload then
|
if fileHandles[fileHandle].needUpload then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user