Автор: Zloy_Gelud
Дата сообщения: 20.09.2014 10:35
dallas page -- если использовать WebDAV, то код будет приблизительно таким (нужны LuaCom и MemoryEx):
Код: Crypto.Base64Encode = function (sData)
local sEnc
local Crypt32 = Library.Load('Crypt32.dll');
local pbBinary = MemoryEx.Allocate(sData:len());
MemoryEx.LString(pbBinary, MemoryEx.Size(pbBinary), sData);
local pcchString = MemoryEx.Allocate(4);
local nRet = Crypt32.CryptBinaryToStringA(pbBinary, MemoryEx.Size(pbBinary), 1, 0, pcchString);
if (nRet ~= 0) then
local pszString = MemoryEx.Allocate(MemoryEx.DWORD(pcchString));
nRet = Crypt32.CryptBinaryToStringA(pbBinary, MemoryEx.Size(pbBinary), 1, pszString, pcchString);
if (nRet ~= 0) then
sEnc = MemoryEx.String(pszString, -1, MEMEX_ASCII);
end
MemoryEx.Free(pszString);
end
MemoryEx.Free(pcchString);
MemoryEx.Free(pbBinary);
return sEnc or '';
end
local sFilePath = _SystemFolder.."\\calc.exe";
local hFile = io.open(sFilePath, "rb");
local sBinary = hFile:read("*all");
hFile:close();
--***********************************************************************************************************
local tPaths = String.SplitPath(sFilePath);
local sURL = 'https://webdav.yandex.ru/'..tPaths.Filename..tPaths.Extension;
local sLogin = 'login';
local sPass = 'pass';
local sToken = Crypto.Base64Encode(sLogin .. ":" .. sPass);
local sUserAgent = 'Mozilla/5.0 (Windows NT 6.1; rv:35.0) Gecko/20100101 Firefox/35.0';
--***********************************************************************************************************
local sEtag = Crypto.MD5DigestFromFile(sFilePath);
-- SHA-256 посчитан вручную. Нужен скрипт для автоматического подсчета
local sSha256 = '80C10EE5F21F92F89CBC293A59D2FD4C01C7958AACAD15642558DB700943FA22';
local nLen = sBinary:len();
--***********************************************************************************************************
local oHTTP = luacom.CreateObject("WinHttp.WinHttpRequest.5.1");
oHTTP:Open("PUT", sURL, 0);
oHTTP:SetRequestHeader("Host", "webdav.yandex.ru");
oHTTP:SetRequestHeader("Accept", "*/*");
oHTTP:SetRequestHeader("Authorization", "Basic " .. sToken);
oHTTP:SetRequestHeader("User-Agent", sUserAgent);
oHTTP:SetRequestHeader("Etag", sEtag);
oHTTP:SetRequestHeader("Sha256", sSha256);
oHTTP:SetRequestHeader("Expect","100-continue");
oHTTP:SetRequestHeader("Content-Type", "application/binary");
oHTTP:SetRequestHeader("Content-Length", nLen);
oHTTP:Send(sBinary);
oHTTP = nil;
Dialog.Message("", oHTTP.StatusText .. ": " .. oHTTP.Status..": "..sBinary:len(), MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);