Hi,
i use the socket extension to download files.
All the Files are .zip, or .rar files, and have a maxsize of 200 mb.
Now i wrote a little script with the socket extension (i took the example.sp).
But it do not download the hole file, only some parts. When i print the dataSize to the server, and add them, i get the right size of the file, but when i count the receiveData String, it's far too little.
PHP Code:
#include <sourcemod>
#include <socket>
new String:TheUrl[257];
public OnConfigsExecuted()
{
DownloadMap("maps/weapons.zip", "addons/sourcemod/test.zip");
}
public DownloadMap(const String:url[], const String:FileName[])
{
Format(TheUrl, sizeof(TheUrl), url);
new Handle:socket = SocketCreate(SOCKET_TCP, OnSocketError);
new Handle:hFile = OpenFile(FileName, "wb");
SocketSetArg(socket, hFile);
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "files.fpsbanana.com", 80)
}
public OnSocketError(Handle:socket, const errorType, const errorNum, any:hFile)
{
LogError("socket error %d (errno %d)", errorType, errorNum);
CloseHandle(hFile);
CloseHandle(socket);
}
public OnSocketConnected(Handle:socket, any:arg)
{
decl String:requestStr[256];
Format(requestStr, sizeof(requestStr), "GET /%s HTTP/1.0\r\nHost: %s\r\nConnection: close\r\n\r\n", TheUrl, "files.fpsbanana.com");
SocketSend(socket, requestStr);
}
public OnSocketReceive(Handle:socket, String:receiveData[], const dataSize, any:hFile)
{
new symbols = strlen(receiveData);
PrintToServer("%i - %i", symbols, dataSize)
WriteFileString(hFile, receiveData, false);
}
public OnSocketDisconnected(Handle:socket, any:hFile)
{
CloseHandle(hFile);
CloseHandle(socket);
}
__________________