View Single Post
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 12-05-2018 , 06:34   Re: [EXTENSION] System2 - Easy to use HTTP(S)/FTP Request API and useful system nativ
Reply With Quote #105

Quote:
Originally Posted by 694372459 View Post
Hi, thanks for replying

here's my code:

PHP Code:
#include <sourcemod>
#include <system2>

#define FTP_HOST ""
#define FTP_PORT
#define FTP_USER ""
#define FTP_PWD ""
#define FTP_REQUEST_FILE ""

public OnPluginStart()
{
    
RegServerCmd("test_ftp_download"Command_TestDownload);
}

public 
Action:Command_TestDownload(args)
{
    
System2FTPRequest ftpRequest = new System2FTPRequest(FtpResponseCallbackFTP_REQUEST_FILE);
    
ftpRequest.SetAuthentication(FTP_USERFTP_PWD);
    
ftpRequest.SetPort(FTP_PORT);
    
ftpRequest.SetOutputFile("addons/sourcemod/data/test_ftp_download.txt");
    
ftpRequest.StartRequest(); 
    
delete ftpRequest;
    
    return 
Plugin_Handled;
}

public 
void FtpResponseCallback(bool success, const char[] errorSystem2FTPRequest requestSystem2FTPResponse response) {
    if (
success) {
        
char file[PLATFORM_MAX_PATH];
        
request.GetInputFile(filesizeof(file));

        if (
strlen(file) > 0) {
            
PrintToServer("Download Finished");    
        }
    }

Shouldn't you close (delete) the FTP request handle (only) in the callback?

Also avoid mixing old and new syntax
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!

Last edited by Papero; 12-05-2018 at 06:35.
Papero is offline